Funkcja Numpy size() | Pyton

W Pythonie funkcja numpy.size() zlicza liczbę elementów wzdłuż danej osi.

Składnia: numpy.size(arr, oś=Brak)
Parametry:
Arr: [array_like] Dane wejściowe.
oś: [int, opcjonalnie] Oś (x, y, z), wzdłuż której liczone są elementy (wiersze lub kolumny). Domyślnie podawaj całkowitą liczbę elementów w tablicy
Zwroty: [int] Zwraca liczbę elementów wzdłuż danej osi.

Kod nr 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))>

Wyjście:

8 

Kod nr 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> ))>

Wyjście:

2 4