Both numpy.shape(a) and a.shape seem to provide the shape of the array a. Which is the better method and why?
Both numpy.shape(a) and a.shape seem to provide the shape of the array a. Which is the better method and why?
For a numpy array, there is almost no perceptible difference between np.shape and np.ndarray.shape. There may be some minimal differences in timing because of overhead, but the functionality is the same.
Numpy functions accept not only arrays, but also array-likes. So you can do something like
np.shape([1, 2, 3])
But NOT
[1, 2, 3].shape