why do i see (m, ) as shape of array and not (m,1)?
- User
why do i see (m, ) as shape of array and not (m,1)?
- Assistant
When you see the shape of an array as
(m, )instead of(m, 1), it means that the array is a 1-dimensional array or a vector, rather than a 2-dimensional array.In numpy, the distinction between a 1-dimensional array and a 2-dimensional array with a single column is sometimes subtle. When you create an array with a single column using
numpy'sreshapeornewaxisoperator, it may be represented as(m, )instead of(m, 1).For example, consider the following code:
codeimport numpy as np arr = np.array([1, 2, 3, 4, 5]) arr_reshape = arr.reshape((5, 1)) print(arr_reshape.shape) # Output: (5, )In this case,
arr_reshapeis a 2-dimensional array with 5 rows and 1 column. However, when you print the shape ofarr_reshape, it shows , as numpy treats it as a 1-dimensional array.