numpy.array()
is just a method which returns an array object of the type ndarray
.
Since the name of the method is array, developers who are new to Python often tend to confuse that numpy.array
returns an array object of some “array
” type. This is not the case.
Following Python code snippet makes this clear
diff_btw_numpy_array_and_ndarray.py
from numpy import array M = array([ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]) # Display the matrix print(M) # What is the type of the array created? print(type(M)) # Check the module name of the array type print(type(M).__module__)
Running the above code gives the following output:
[[1 2 3] [4 5 6] [7 8 9]] <class 'numpy.ndarray'> numpy
Difference between ndarray and array in numpy