size and shape in python

Size and shape are functions in numpy.
size() calculates the number of all elements in the matrix;
shape() returns the dimension value. which is

import numpy as np

a = np.array([[1,2,3],[4,5,6],[7,8,9]])
print(np.size(a))
print(np.shape(a))

The return result is

9
(3, 3)

shape[0] returns the number of rows, shape[1] returns the number of columns

b = a.shape[0]
print(b)

return

3

Note that when writing

b = a.shape(0

When, it will report an error

TypeError: 'tuple' object is not callable

Guess you like

Origin blog.csdn.net/Peggiehu/article/details/107004480