python怎么引入mean函数

554
2021/2/14 8:47:22
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

python怎么引入mean函数

在python中使用mean函数的方法

mean():mean函数中作用是求取均值。

mean函数使用方法:

import numpy as np

num1 = np.array([[1,2,3],[2,3,4],[3,4,5],[4,5,6]])

now2 = np.mat(num1)

now2

matrix([[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.]])

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: Python多线程怎么修改类变量