去掉数组Python中的格式e+xx
我正试图摆脱这种格式,使这个文件在另一个软件中可读去掉数组Python中的格式e+xx,python,arrays,Python,Arrays,我正试图摆脱这种格式,使这个文件在另一个软件中可读 import numpy as np test=[5.1056e+02, 6.89752e+05, 4.5987126464655e+03] np.round(test,6) print(test) test2=[[5.1056e+02, 6.89752e+05, 4.5987126464655e+03],[5.1056e+02, 6.89752e+05, 4.5987126464655e+03]] test2=np.array(test2
import numpy as np
test=[5.1056e+02, 6.89752e+05, 4.5987126464655e+03]
np.round(test,6)
print(test)
test2=[[5.1056e+02, 6.89752e+05, 4.5987126464655e+03],[5.1056e+02, 6.89752e+05, 4.5987126464655e+03]]
test2=np.array(test2)
np.round(test2,6)
print(test2)
第一版给了我:
[510.56, 689752.0, 4598.7126464655]
[[ 5.10560000e+02 6.89752000e+05 4.59871265e+03]
[ 5.10560000e+02 6.89752000e+05 4.59871265e+03]]
[[ 5.10560000e+02 6.89752000e+05 4.59871265e+03]
[ 5.10560000e+02 6.89752000e+05 4.59871265e+03]]
第二次印刷给了我:
[510.56, 689752.0, 4598.7126464655]
[[ 5.10560000e+02 6.89752000e+05 4.59871265e+03]
[ 5.10560000e+02 6.89752000e+05 4.59871265e+03]]
[[ 5.10560000e+02 6.89752000e+05 4.59871265e+03]
[ 5.10560000e+02 6.89752000e+05 4.59871265e+03]]
现在第一个结果对我来说很好,但是我的数据看起来像test2。但是我仍然不明白np.round的第二个参数是什么,因为它应该限制小数的数量,但是我仍然得到4598.71264655。
但至少我得到了一个可用的格式
我怎样才能在test2这样的东西上工作呢?
我试过这个:
for i in range(np.shape(test2)[0]):
np.round(test2[i])
print(test2)
仍然给我:
[510.56, 689752.0, 4598.7126464655]
[[ 5.10560000e+02 6.89752000e+05 4.59871265e+03]
[ 5.10560000e+02 6.89752000e+05 4.59871265e+03]]
[[ 5.10560000e+02 6.89752000e+05 4.59871265e+03]
[ 5.10560000e+02 6.89752000e+05 4.59871265e+03]]
所以你的取整很好
打印前。np.roundtest,6不会修改测试对象本身。它返回一个新对象。所以你必须做test=np.roundtest,6不,它没有。看起来像,但不是。OP没有指定轮的返回值。除了即使在我做了这些更改之后,它也不能解决我的科学格式e+xx的问题