Which is a better to call certain numpy methods?

Viewed 26

Both numpy.shape(a) and a.shape seem to provide the shape of the array a. Which is the better method and why?

1 Answers

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
Related