8. Write a Python Numpy program to convert both list a and tuple b in the following output to numpy array.
The output is:
list_a = [1, 2, 3, 4, 5, 6, 7, 8]
tuple_b = (1, 2, 3, 4, 5, 6, 7, 8)
Expected Answer:
List to array:
[1 2 3 4 5 6 7 8]
Tuple to array:
[1 2 3 4 5 6 7 8]
Sample Answer:
import numpy as np
list_a = [1, 2, 3, 4, 5, 6, 7, 8]
print("List to array: ")
print(np.asarray(my_list))
tuple_b = (1, 2, 3, 4, 5, 6, 7, 8)
print("\nTuple to array: ")
print(np.asarray(my_tuple))
More Exercises:
Python String ExercisesMore Numpy Exercises:
Numpy String ExercisesMore Pandas Exercises:
Pandas Series ExercisesMore Tutorials:
Python Installation - Linux (Ubuntu)