如何在python中计算平均值?

 fuzhipai 发布于 2023-02-13 13:56

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

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: cannot perform reduce with flexible type

我试图找到一些帮助,但没有找到有用的东西

谢谢你们.

1 个回答
  • 将列表从字符串转换为np.float:

    >>> gp = np.array(goodPix, np.float)
    >>> np.mean(gp)
    96.906260000000003
    

    2023-02-13 13:59 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有