首页 > 解决方案 > 当我们指定负小数时,函数如何工作

问题描述

我正在使用 numpy 函数。我已经在数组 a = np.array([1.0,5.55,123,0.567,25.532]) 上应用了函数这将返回以下结果:[ 0. 10. 120. 0. 30.] 我不明白第二个元素变成10?

任何建议都会有所帮助

标签: python-3.xnumpy

解决方案


如果没有看到你的完整代码,我不能确定,但​​看起来你已经到了-1一些地方 - 到了 10s 的地方。考虑以下:

for scale in [2,1,0,-1,-2]:
    print(f'round(555.555, {scale})\t= {round(555.555, scale)}')
round(555.555,  2)  = 555.55
round(555.555,  1)  = 555.6
round(555.555,  0)  = 556.0
round(555.555, -1)  = 560.0
round(555.555, -2)  = 600.0

推荐阅读