我有一个具有以下结构的 numpy.ndarray:
array([[ 7963.92759169, -2931.3518914 , 3360.79428745],
[ 7964.28495515, -2930.99452794, 3361.15165092],
[ 7965.60367246, -2929.67581063, 3362.47036823]])
我尝试使用以下代码将小数点后的数字限制为 2:
for (label, score) in zip(lables, scoring_fn):
print("[INFO] {}: {:.2f}".format(label, float(score)))
这样,我收到错误“TypeError:不支持的格式字符串传递给 numpy.ndarray。格式”。谁能建议如何纠正这个错误?
最佳答案
或者使用np.ndarray.round
:
arr = arr.round(2)
关于python - 在 Python 中使用 Format 时出现类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57668612/