使用 {n}。格式()
例如:'{:n}'.format(1234))
ds_x=[ 0.00000000e+00, 0.00000000e+00, 1.00000000e+00,1.65349200e+05, 1.36897800e+05, 4.71784100e+05]
# For Numpy arrays use '.astype'
# Copy of the array 'ds_x', cast to a specified type 'float'.
# Note: Try type 'float32' OR 'float64' if the below fails to provide correct precision.
data_set = ds_x.astype(float)
for i in data_set:
print("{:.16f}".format(float(i)))
# 更多关于更好的精度可以找到here
输出:
0.0000000000000000
0.0000000000000000
1.0000000000000000
165349.2000000000116415
136897.7999999999883585
471784.0999999999767169
或者您可以使用其他方式:
"%.16f" % (float( 00,1.65349200e+05))
关于 PyCharm 的第二个问题。您可能想查看 formatting markers 。 reformatting 的完整详细信息。
更新:
这是您提供的数据集的更新代码示例。
import numpy as np
ds = np.array([[ 0.00000000e+00, 1.00000000e+00, 0.00000000e+00, 2.86637600e+04, 1.27056210e+05, 2.01126820e+05],
[ 0.00000000e+00, 0.00000000e+00, 1.00000000e+00, 1.44372410e+05, 1.18671850e+05, 3.83199620e+05]])
for data_x in iter(ds):
print()
for data_y in data_x:
print("%.16f" % float(data_y))
输出:
0.0000000000000000
1.0000000000000000
0.0000000000000000
28663.7599999999983993
127056.2100000000064028
201126.8200000000069849
0.0000000000000000
0.0000000000000000
1.0000000000000000
144372.4100000000034925
118671.8500000000058208
383199.6199999999953434
关于错误:
TypeError:只有 size-1 的数组可以转换为 Python 标量
这是因为您使用的数据集是 Python 矩阵或一个列表/两个数组的列表。这篇文章中的第一个代码示例是使用一个与一个数组一起工作的循环;但是,由于您在第一个循环中使用包含两个数组的较大数据集,因此它将传递整个数组,从而导致输出上述错误。为了纠正这个问题,我简单地添加了第二个循环来遍历每个数组的每个值。