python在array中找数据_在Python中找到Numpy数组列表的平均值

Numpy是一个非常强大的用于数字数据处理的python库。它主要以数组形式获取数据,并应用各种功能(包括统计功能)将结果从数组中取出。在本文中,我们将看到如何获取给定数组的平均值。

刻薄

平均值函数可以接受数组,并给出数组中所有元素的数学平均值。因此,我们设计了一个for循环来跟踪输入的长度,并遍历每个数组计算其平均值。

示例import numpy as np

# GIven Array

Arrays_In = [np.array([11, 5, 41]),

np.array([12, 13, 26]),

np.array([56, 20, 51])]

# Resultihg Array

Arrays_res = []

# With np.mean()

for x in range(len(Arrays_In)):

Arrays_res.append(np.mean(Arrays_In[x]))

# Result

print("The means of the arrays: \n",Arrays_res)

输出结果

运行上面的代码给我们以下结果-The means of the arrays:

[19.0, 17.0, 42.333333333333336]

平均

除了我们使用平均值函数代替均值函数外,它与上述方法非常相似。它给出了完全相同的结果。

示例import numpy as np

# GIven Array

Arrays_In = [np.array([11, 5, 41]),

np.array([12, 13, 26]),

np.array([56, 20, 51])]

# Resultihg Array

Arrays_res = []

# With np.average()

for x in range(len(Arrays_In)):

Arrays_res.append(np.average(Arrays_In[x]))

# Result

print("The means of the arrays: \n",Arrays_res)

输出结果

运行上面的代码给我们以下结果-The means of the arrays:

[19.0, 17.0, 42.333333333333336]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值