[[0.0000000e+00 0.0000000e+00 1.0000000e+00 1.6534920e+05 1.3689780e+05
4.7178410e+05]
[1.0000000e+00 0.0000000e+00 0.0000000e+00 1.6259770e+05 1.5137759e+05
4.4389853e+05]
[0.0000000e+00 1.0000000e+00 0.0000000e+00 1.5344151e+05 1.0114555e+05
4.0793454e+05]
[0.0000000e+00 0.0000000e+00 1.0000000e+00 1.4437241e+05 1.1867185e+05
3.8319962e+05]
[1.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 1.1698380e+05
4.5173060e+04]]
我应如何更改矩阵的值,以将其四舍五入为%0f格式?
最佳答案
您可以使用numpy's vectorize函数并传递要应用于列表的函数:
import numpy as np
rfunc = np.vectorize(round) # round() is a python function which rounds inputs to a precision set by number of decimals; e.g: np.round(2.3456, 1) returns 2.3
rfunc(a, 2) # 2 is the precision which needs to be adjusted
关于python - 如何在python中更改矩阵值的格式?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59599021/