I am not aware of anything in the standard library. However, you could use something like:
def mean(numbers):
return float(sum(numbers)) / max(len(numbers), 1)
>>> mean([1,2,3,4])
2.5
>>> mean([])
0.0
In numpy, there’s numpy.mean()
.
More Related Contents:
- Accessing the index in ‘for’ loops
- Get a list of numbers as input from the user
- python list by value not by reference [duplicate]
- Why does this code for initializing a list of lists apparently link the lists together? [duplicate]
- Access multiple elements of list knowing their index
- Comparing two lists using the greater than or less than operator
- Appending the same string to a list of strings in Python
- Removing item from list causes the list to become NoneType
- Why is [] faster than list()?
- How can I multiply all items in a list together with Python?
- How to unzip a list of tuples into individual lists? [duplicate]
- Remove trailing newline from the elements of a string list
- Getting only element from a single-element list in Python?
- In Python, what is the fastest algorithm for removing duplicates from a list so that all elements are unique *while preserving order*? [duplicate]
- list() uses slightly more memory than list comprehension
- Generating sublists using multiplication ( * ) unexpected behavior [duplicate]
- Appending to the same list from different processes using multiprocessing
- Python: How to remove empty lists from a list? [duplicate]
- How to use python numpy.savetxt to write strings and float number to an ASCII file?
- Checking if any elements in one list are in another [duplicate]
- python: most elegant way to intersperse a list with an element
- Converting a string that represents a list, into an actual list object
- Merging/adding lists in Python
- how to keep elements of a list based on another list [duplicate]
- Flatten an irregular (arbitrarily nested) list of lists
- How to concatenate (join) items in a list to a single string
- “TypeError: ‘type’ object is not subscriptable” in a function signature
- Ellipsis lists […] and concatenating a list to itself [duplicate]
- Creating a list in Python with multiple copies of a given object in a single line
- Python : how to append new elements in a list of list?