-1

我有一个数据列表,例如A = [1,2,3,10,4,3.5,16,11,19,6,13] 现在我想在条目值小于 10 时找到该数据集的平均值。我该如何在 Python 中做到这一点?

4

2 回答 2

2

您可以使用列表切片获取子列表-A[start:stop:step]

python3.*

>>> sum(A[:10]) / 10    # 10:is length of your sublist
5.5

python2.*

>>> from __future__ import division   # to get float division like python3
>>> sum(A[:10]) / 10    # 10:is length of your sublist
5.5
于 2020-01-30T08:36:05.943 回答
2

您可以使用statistics.mean

from statistics import mean

a = [1,2,3,4,5,6,7,8,9,10]
print(mean(a)) # 5.5
于 2020-01-30T08:34:57.033 回答