Numpy Question about np.array

What is the difference between np.array and np.ndarray? I’ve messed around with them in a separate document and they seem to operate in the same way.

The NumPy documentation explains. In short, np.array is a function that allows one to create an array, typically from a Python list or a list of lists, or even higher-order nested lists).

For example, my_array = np.array([[1, 2, 3], [4, 5, 6]]) will create a NumPy array with two rows and three columns. The object created is of type np.ndarray–shorthand for “N-dimensional array.” You can verify this by applying the Python function type: type(my_array) will return the object type numpy.ndarray.

2 Likes