NumPy is designed for working with arrays, and its array object is called ndarray.
You can create a NumPy ndarray object using the array() function.
import numpy as np arr = np.array([1, 2, 3, 4, 5]) print(arr) print(type(arr)) |
To create an ndarray, you can pass a list, tuple, or any array-like object to the array() method, which will convert it into an ndarray.
Create a NumPy array using a tuple:
import numpy as np arr = np.array((1, 2, 3, 4, 5)) print(arr) |