Funkcija Numpy size() | Python

V Pythonu funkcija numpy.size() šteje število elementov vzdolž dane osi.

Sintaksa: numpy.size(arr, axis=None)
Parametri:
prihod: [array_like] Vhodni podatki.
os: [int, neobvezno] Os(x,y,z), vzdolž katere se štejejo elementi (vrstice ali stolpci). Privzeto navedite skupno število elementov v matriki
Vrne: [int] Vrne število elementov vzdolž dane osi.

Koda #1:

Python3




# Python program explaining> # numpy.size() method> # importing numpy> import> numpy as np> # Making a random array> arr> => np.array([[> 1> ,> 2> ,> 3> ,> 4> ], [> 5> ,> 6> ,> 7> ,> 8> ]])> # By default, give the total number of elements.> print> (np.size(arr))>

Izhod:

8 

Koda #2:

Python3




# Python program explaining> # numpy.size() method> # importing numpy> import> numpy as np> # Making a random array> arr> => np.array([[> 1> ,> 2> ,> 3> ,> 4> ], [> 5> ,> 6> ,> 7> ,> 8> ]])> # count the number of elements along the axis.> # Here rows and columns are being treated> # as elements> #gives no. of rows along x-axis> print> (np.size(arr,> 0> ))> #gives no. of columns along y-axis> print> (np.size(arr,> 1> ))>

Izhod:

2 4