python - 如何在python中计算均值?

标签 python list numpy average mean

我有一个列表,我想为她计算值的平均值(均值?)。 当我这样做时:

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/

相关文章:

c# - 在另一个 List<string> 中匹配 List<string> 中的部分字符串

python - 将元素 append 到 numpy 数组中每个箭头的末尾

python - 有没有办法在没有 scipy 其余部分的情况下安装 scipy 特殊模块?

numpy - 如何查找数组中的任何列是否有重复值

python - Pyplot 填充线下方区域

python - 如何从包含年份和月份的单个日期列中为每年创建一个列?

python - 这个错误 InvalidArgumentError (see above for traceback) : Expected dimension in the range [-1, 1), but got 1 是什么意思?

Python for循环按类别分隔

python - 一个 pygame Sprite 列表丢失了它的第一个元素,并获得了最后一个元素的副本

python - 我想用列表中的双引号替换单引号