Python의 numpy.round_()
그만큼 numpy.round_() 배열을 주어진 소수 자릿수로 반올림하는 수학 함수입니다.
구문: numpy.round_(arr, 소수점 = 0, 출력 = 없음)
매개변수:
배열 : [배열_유사] 입력 배열.
십진수 : [정수, 선택 사항] 반올림하려는 소수점 자리입니다.기본값 = 0. -ve 소수의 경우 n0을 지정합니다. 소수점 왼쪽 위치.
밖으로 : [선택 과목] 출력 결과 배열
반품 :
An array with all array elements being rounded off, having same type as input.
코드 #1 : 작동 중
# Python program explaining> # round_() function> import> numpy as np> > in_array> => [.> 5> ,> 1.5> ,> 2.5> ,> 3.5> ,> 4.5> ,> 10.1> ]> print> (> 'Input array :
'> , in_array)> > round_off_values> => np.round_(in_array)> print> (> '
Rounded values :
'> , round_off_values)> > > in_array> => [.> 53> ,> 1.54> , .> 71> ]> print> (> '
Input array :
'> , in_array)> > round_off_values> => np.round_(in_array)> print> (> '
Rounded values :
'> , round_off_values)> > in_array> => [.> 5538> ,> 1.33354> , .> 71445> ]> print> (> '
Input array :
'> , in_array)> > round_off_values> => np.round_(in_array, decimals> => 3> )> print> (> '
Rounded values :
'> , round_off_values)> |
출력 :
Input array : [0.5, 1.5, 2.5, 3.5, 4.5, 10.1] Rounded values : [ 0. 2. 2. 4. 4. 10.] Input array : [0.53, 1.54, 0.71] Rounded values : [ 1. 2. 1.] Input array : [0.5538, 1.33354, 0.71445] Rounded values : [ 0.554 1.334 0.714]
코드 #2: 작동 중
# Python program explaining> # round_() function> import> numpy as np> > in_array> => [> 1> ,> 4> ,> 7> ,> 9> ,> 12> ]> print> (> 'Input array :
'> , in_array)> > round_off_values> => np.round_(in_array)> print> (> '
Rounded values :
'> , round_off_values)> > > in_array> => [> 133> ,> 344> ,> 437> ,> 449> ,> 12> ]> print> (> '
Input array :
'> , in_array)> > round_off_values> => np.round_(in_array, decimals> => -> 2> )> print> (> '
Rounded values upto 2:
'> , round_off_values)> > in_array> => [> 133> ,> 344> ,> 437> ,> 449> ,> 12> ]> print> (> '
Input array :
'> , in_array)> > round_off_values> => np.round_(in_array, decimals> => -> 3> )> print> (> '
Rounded values upto 3:
'> , round_off_values)> |
출력 :
Input array : [1, 4, 7, 9, 12] Rounded values : [ 1 4 7 9 12] Input array : [133, 344, 437, 449, 12] Rounded values upto 2: [100 300 400 400 0] Input array : [133, 344, 437, 449, 12] Rounded values upto 3: [0 0 0 0 0]