I'm currently trying to learn Numpy and Python. Given the following array:
import numpy as np a = np.array([[1,2],[1,2]])
Is there a function that returns the dimensions of
a (e.g.a is a 2 by 2 array)?
size() returns 4 and that doesn't help very much.
By convention, in Python world, the shortcut for
In : import numpy as np In : a = np.array([[1,2],[3,4]])
In Numpy, dimension, axis/axes, shape are related and sometimes similar concepts:
In Mathematics/Physics, dimension or dimensionality is informally defined as the minimum number of coordinates needed to specify any point within a space. But in Numpy, according to the numpy doc, it's the same as axis/axes:
In Numpy dimensions are called axes. The number of axes is rank.
In : a.ndim # num of dimensions/axes, *Mathematics definition of dimension* Out: 2
the nth coordinate to index an
array in Numpy. And multidimensional arrays can have one index per axis.
In : a[1,0] # to index `a`, we specific 1 at the first axis and 0 at the second axis. Out: 3 # which results in 3 (locate at the row 1 and column 0, 0-based index)
describes how many data (or the range) along each available axis.
In : a.shape Out: (2, 2) # both the first and second axis have 2 (columns/rows/pages/blocks/...) data