What number represent the rows and columns in the tuple returned by the form?

>>> A = np.matrix(np.zeros(2, 3)))  
>>> A.shape  
(2, 3)  
>>> A  
matrix([[ 0.,  0.,  0.],
        [ 0.,  0.,  0.]])

      

Does the matrix have A

two rows with three zeros or two columns with three zeros?

+3


source to share


3 answers


rows

, columns

are just the names we give, by convention, to the two dimensions of a matrix

(or more generally to a 2d numpy array).

np.matrix

is, by definition, 2d, so this convention is useful. But it np.array

can have 0, 1, 2 or more dimensions. For this, these 2 names are less useful. For example if 1d does it have rows or columns? If 3d, what do we call the last dimension, depth? or maybe the first pages?



So don't put too much emphasis on names. Most functions numpy

require you to specify "axis", number, 0, 1, 2, etc., rather than by name.

Additional confusion may arise if you load data from a csv file and get a 1d array (one line per line in the file) of dtype fields. Are the fields the same as columns? Sorting, but not quite.

+3


source


A.shape

will return a tuple (m, n), where m is the number of rows and n is the number of columns.



+11


source


The corresponding matrix has 2 rows and 3 columns (dimension 2x3), where each of the matrix elements is zero.

+2


source







All Articles