Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np
my_list = [1, 2, 3, 4, 5, 6, 7, 8]
print("List to array: ")
print(np.asarray(my_list))
my_tuple = ([8, 4, 6], [1, 2, 3])
print("Tuple to array: ")
print(np.asarray(my_tuple))

Sample Output:

List to array:                                                          
[1 2 3 4 5 6 7 8]                                                       
Tuple to array:                                                         
[[8 4 6]                                                                
 [1 2 3]]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now