pythonarraysnumpydimensions

Numpy array dimensions


How do I get the dimensions of an array? For instance, this is 2x2:

a = np.array([[1, 2], [3, 4]])

Solution

  • Use .shape to obtain a tuple of array dimensions:

    >>> a.shape
    (2, 2)