x = np.array([1,2,3])
x.shape would return (3,) without specify the dimension
However, if I have
x = no.array([[1,2,3],[1,2,3]])
x.shape would return (2,3) and the first number in the tuple is the dimension of an array whereas the second represent the dimension.
Could anyone explain for why is there such different?
Your first np.array() example returns a 1D vector.
Your second np.array() example returns a 2D matrix. The shape returns (rows , columns).
Oh, so it means that the shape return (m,n) where m is rows and n is col right?
I read that the dimension of an array it is the number of the indexes of an array.
But why np.array([[1,2],[2,3],[3,4]]) would return (3,2)
The number of indexes of an array is 3, but clearly this is 2D array not 3D array
And does it means that len(x.shape) would return how many dimensions of an arrays right
(for example, (2,3) return 2-D arrays, (2,3,4) return 3-D arrays)
Hello @David5804,
In numpy, dimension is the number of axes. A shape of (3, 2) means the corresponding array is 2-dimensional because it has 2 axes, the zeroth axis has valid index values from 0 to 2, whereas the first axis has valid index values from 0 to 1.
Raymond