python how the number of rows and columns of the matrix output?

How to output the number of rows and columns matrix Python?

For matrix or table data definition pyhton or introduced inside, there is a method and want to get the number of columns the number of rows of the matrix:

1, using the shape function output columns and rows of the matrix

Sequence x.shape function may output a tuple (m, n), wherein a first number m of tuple represents the number of rows of the matrix, the second number of tuples in a matrix of n

Specific code as follows:

AS NP numpy Import
X = np.array ([[1, 2,5], [2,3,5], [3,4, 5], [2,3,6]])
line and the output array # columns
Print (x.shape) # (. 4,. 3)
# output only the number of rows
Print (x.shape [0]). 4 #
# output only the number of columns
print (x.shape [1]) # 3

2, to the number of rows of the matrix, may cause (x) function len matrix output length , the so-called rows.

AS NP numpy Import
([[2,3,6] [1, 2,5], [2,3,5], [3,4, 5],]) = X np.array
# number of rows of the output array
print (len (x)) # 4

3, using x.ndim function may output matrix dimension, i.e. the number of columns

AS NP numpy Import
([[2,3,6] [1, 2,5], [2,3,5], [3,4, 5],]) = X np.array
# number of rows of the output array
print (x.ndim) # 3

Guess you like

Origin www.cnblogs.com/Yanjy-OnlyOne/p/11298253.html