我有一个列表,我想为她计算值的平均值(均值?)。 当我这样做时:
import numpy as np #in the beginning of the code
goodPix = ['96.7958', '97.4333', '96.7938', '96.2792', '97.2292']
PixAvg = np.mean(goodPix)
我收到此错误代码:
ret = um.add.reduce(arr, axis=axis, dtype=dtype, out=out, keepdims=keepdims)
TypeError: 无法使用灵活类型执行 reduce
我试图寻求一些帮助,但没有找到有用的东西
谢谢大家
最佳答案
将列表从字符串转换为 np.float:
>>> gp = np.array(goodPix, np.float)
>>> np.mean(gp)
96.906260000000003
关于python - 如何在python中计算均值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20329746/