Numpy size() funktion | Python

I Python tæller funktionen numpy.size() antallet af elementer langs en given akse.

Syntaks: numpy.size(arr, axis=Ingen)
Parametre:
arr: [array_like] Inputdata.
akse: [int, valgfri] Akse(x,y,z), langs hvilken elementerne (rækker eller kolonner) tælles. Angiv som standard det samlede antal elementer i en matrix
Vender tilbage: [int] Returner antallet af elementer langs en given akse.

Kode #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))>

Produktion:

8 

Kode #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> ))>

Produktion:

2 4