Python numpy.ceil()を数値の小数点第二位を切り上げるサンプル

環境
Windows 11 Pro 64bit
Python 3.11

構文
numpyをインポートします。
import numpy
numpyからceil()を呼び出します。
numpy.ceil()の引数に10を掛けた数値を指定します。
numpy.ceil()の結果を10で割ります。
result = numpy.ceil(value * 10) / 10

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import numpy as np
result1 = np.ceil(2.42 * 10) / 10
result2 = np.ceil(20.24 * 10) / 10
result3 = np.ceil(4.311111 * 10) / 10
print(result1)
print(result2)
print(result3)
import numpy as np result1 = np.ceil(2.42 * 10) / 10 result2 = np.ceil(20.24 * 10) / 10 result3 = np.ceil(4.311111 * 10) / 10 print(result1) print(result2) print(result3)
import numpy as np

result1 = np.ceil(2.42 * 10) / 10
result2 = np.ceil(20.24 * 10) / 10
result3 = np.ceil(4.311111 * 10) / 10

print(result1) 
print(result2) 
print(result3)

実行結果
2.5
20.3
4.4

IT

Posted by arkgame