To create a numpy array, first you have to import the numpy library into your code
import numpy as np
Then, use numpy array
method to create the numpy array and pass a python list as its argument
list_of_number = [1, 2, 3, 4, 5]
arr = np.array(list_of_number)
Not only you can pass a python list as the argument of array
method, you can also pass a python tuple
tuple_of_number = (1, 2, 3, 4, 5)
arr = np.array(tuple_of_number)
When you print the array,
print(arr)
you will see the following output
[1 2 3 4 5]
There you go, you have created a NumPy array. Thank you for reading this blog, and see you next time!
Top comments (0)