python列表查找值_在Python中查找列表平均值的5种方法

本文介绍了在Python中计算列表平均值的五种方法:1) 使用mean()函数;2) 利用sum()函数和列表长度;3) 结合reduce()和lambda方法;4) 使用operator.add()函数;5) 应用NumPy的average()方法。通过这些技术,可以高效地计算Python列表的平均值。
摘要由CSDN通过智能技术生成

python列表查找值

Hi Folks! In this article, we will have a look at the various ways to find the average of a list in a Python List.

嗨伙计! 在本文中,我们将介绍在Python List中查找列表平均值的各种方法

In general, an average is a value that represents a whole set of data items or elements.

通常,平均值是代表整个数据项或元素集的值。

Formula: Average = summation of numbers/total count.

公式:平均值=数字总和/总计数。



在Python中查找列表平均值的技巧 (Techniques to find the average of a list in Python)

Either of the following techniques can be used to calculate the average/mean of a list in Python:

以下任何一种技术均可用于计算Python中列表的平均值/均值:

  • Python mean() function

    Python mean()函数
  • In-built sum() method

    内置sum()方法
  • Python lambda and reduce() method

    Python Lambda和reduce()方法
  • Python operator.add() method

    Python operator.add()方法


1. Python mean()函数 (1. Python mean() function)

Python 3 has statistics module which contains an in-built function to calculate the mean or average of numbers. The statistics.mean() function is used to calculate the mean/average of input values or data set.

Python 3具有statistics module ,该statistics module包含一个内置函数来计算数字的均值或平均值。 statistics.mean() function用于计算输入值或数据集平均值/平均值

The mean() function accepts the list, tuple or data-set containing numeric values as a parameter and returns the average of the data-items.

mean()函数接受包含数值的列表,元组或数据集作为参数,并返回

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值