Numpy size() 함수 | 파이썬
Python에서 numpy.size() 함수는 주어진 축을 따라 요소 수를 계산합니다.
통사론: numpy.size(arr, 축=없음)
매개변수:
도착: [array_like] 입력 데이터입니다.
중심선: [int, 선택사항] 요소(행 또는 열)가 계산되는 축(x,y,z)입니다. 기본적으로 배열의 총 요소 수를 제공합니다.
보고: [int] 주어진 축을 따라 요소 수를 반환합니다.
코드 #1:
파이썬3
# 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))> |
산출:
8
코드 #2:
파이썬3
# 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> ))> |
산출:
2 4