๐Ÿ
B.TECH I YEAR โ€ข II SEMESTER โ€ข R25

Python Programming - Lab Manual

Python Programming Laboratory โ€ข Program Solution

๐Ÿ“˜ R25 Regulation ๐ŸŽ“ I Year ๐Ÿ“š II Semester ๐Ÿ Python Programming ๐Ÿงช Lab Program
Selected Program

convert a list and tuple into arrays

โ† All Python Programs

Aim:

☛   Write a program to convert a list and tuple into arrays

Solution :


PROGRAM: (convert.py)

 
import numpy as np
list = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ]
print ( " List to array: " )
array_1 = np . asarray ( list )
print ( type ( array_1 ) )
print ( array_1 )
print ( )
print ( )
tuple = ( [ 8, 4 , 6 ] , [ 1 , 2 , 3 ] )
print ( " Tuple to array: " )
array_2 = np . asarray ( tuple )
print ( type ( array_2 ) )
print ( array_2 )

OUTPUT:

 
List to array:
< class ' numpy . ndarray ' >
[ 1 2 3 4 5 6 7 8 ]
Tuple to array:
< class ' numpy . ndarray ' >
[ [ 8 4 6 ]
 [ 1 2 3 ] ]


๐Ÿ’ป Run This Python Program

convert a list and tuple into arrays
The selected Python program is loaded automatically into the editor. Edit the program, provide input if required and click Run.

The compiler is embedded using OneCompiler. Your Python program runs inside the embedded Python environment; Study Glance does not execute Python code directly on your web server.
โ† Back to Python Lab Programs ๐Ÿ“š All Lab Manuals