(3,) does not mean the 3 is first. It is simply the Python way of writing a 1-element tuple. If the shape were a list instead, it would be [3].
(, 3) is not valid Python. The syntax for a 1-element tuple is (element,).
The reason it can't be just (3) is that Python simply views the parentheses as a grouping construct, meaning (3) is interpreted as 3, an integer.
what's the difference between a numpy array with shape (x,) and (x, 1)?
python - Shape 1 of numpy array - Stack Overflow
python - What does .shape[] do in "for i in range(Y.shape[0])"? - Stack Overflow
What does shape[0] and shape[1] do in python? - Stack Overflow
hey, im doing an ai thing in school and my code didnt work as expected, and after 5 hours i found out i reshaped an array from (206,) to (206,1) and that made the results wrong. and from what i understand, the shape means the length of each dimension, and length is not 0 indexed so a size of 1 would be equal to just 1D no?
(3,) does not mean the 3 is first. It is simply the Python way of writing a 1-element tuple. If the shape were a list instead, it would be [3].
(, 3) is not valid Python. The syntax for a 1-element tuple is (element,).
The reason it can't be just (3) is that Python simply views the parentheses as a grouping construct, meaning (3) is interpreted as 3, an integer.
As you know, numpy arrays are n-dimensional. The shape tells dimensions in the order. If it is 1-D you will see only 1st dimension, 2-D only 2 dimensions and so on.
Here x is a 2-D array while v is a 1-D array (aka vector). That is why when you do shape on v you see (3,) meaning it has only one dimension whereas x.shape gives (4,3). When you transpose v, then that is also a 1-D array. To understand this better, try another example. Create a 3-D array.
z=np.ones((5,6,7))
z.shape
print (z)
The shape attribute for numpy arrays returns the dimensions of the array. If Y has n rows and m columns, then Y.shape is (n,m). So Y.shape[0] is n.
In [46]: Y = np.arange(12).reshape(3,4)
In [47]: Y
Out[47]:
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]])
In [48]: Y.shape
Out[48]: (3, 4)
In [49]: Y.shape[0]
Out[49]: 3
shape is a tuple that gives dimensions of the array..
>>> c = arange(20).reshape(5,4)
>>> c
array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11],
[12, 13, 14, 15],
[16, 17, 18, 19]])
c.shape[0]
5
Gives the number of rows
c.shape[1]
4
Gives number of columns