How to Get Shape of a Multidimensional Array


In this example we will show how to get the shape of a multidimensional NumPy array in Python.

Source Code

import numpy as np

n = np.array([1, 2, 3, 4, 5], ndmin=6)

print(n)

# last dimension has value 5
print(n.shape)

Output:

[[[[[[1 2 3 4 5]]]]]]
(1, 1, 1, 1, 1, 5)
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments