您的位置 首页 技术

python如何求列表平均值?

推荐教程:《python视频教程》 python如何求列表平均值? python函数求列表平均值的方法: 用法:mean(matrix,axis=0)其中matrix为一个矩阵,a…

推荐教程:《python视频教程》

python如何求列表平均值?

python函数求列表平均值的方法:

用法:mean(matrix,axis=0)其中matrix为一个矩阵,axis为参数

以m * n矩阵举例:

axis不设置值,对 m*n 个数求均值,返回一个实数

axis=0:压缩行,对各列求均值,返回 1* n 矩阵

axis=1:压缩列,对各行求均值,返回 m *1 矩阵

>>>  import numpy as np>>> num1 = np.array([[1,2,3],[2,3,4],[3,4,5],[4,5,6]])>>> now2 = np.mat(num1)>>> now2matrix([[1, 2, 3],        [2, 3, 4],        [3, 4, 5],        [4, 5, 6]])>>> np.mean(now2) # 对所有元素求均值3.5>>> np.mean(now2,0) # 压缩行,对各列求均值matrix([[ 2.5,  3.5,  4.5]])>>> np.mean(now2,1) # 压缩列,对各行求均值matrix([[ 2.],        [ 3.],        [ 4.],        [ 5.]])

推荐相关文章:《python教程》

以上就是python如何求列表平均值?的详细内容,更多请关注24课堂在线网其它相关文章!

本文来自网络,不代表24小时课堂在线立场,转载请注明出处:https://www.24ketang.cn/86626.html

为您推荐

返回顶部