どうも、ちょげ(@chogetarou)です。
numpyを使って、数値の小数点第二位を切り上げる方法を紹介します。
方法

numpyを使って、数値の小数点第2位を切り上げるには、numpyのceil()を使います。
まず、numpyをインポートします。
import numpy
そして、numpyからceil()を呼び出します。
numpy.ceil()の引数に10を掛けた数値を指定します。
numpy.ceil()の結果を10で割ります。
result = numpy.ceil(value * 10) / 10
上記のceil()の結果を10で割った値は、引数に指定した数値の小数点第2位を切り上げた数値になります。
使用例
import numpy as np
result1 = np.ceil(1.42 * 10) / 10
result2 = np.ceil(10.24 * 10) / 10
result3 = np.ceil(3.311111 * 10) / 10
print(result1) #1.5
print(result2) #10.3
print(result3) #3.4
コメント