Gistlib Logo

gistlib

obtain the average of an array in python

To obtain the average of an array in Python, you can sum all the values in the array and divide by the length of the array. Here's an example:

main.py
my_array = [2, 4, 6, 8, 10]

avg = sum(my_array) / len(my_array)

print(avg)
77 chars
6 lines

This will output:

main.py
6.0
4 chars
2 lines

So the average of the my_array is 6.0.

similar python code snippets

find the average of a list of numbers in python
find the average of all elements in an array in python
how to get distinct combinations of a set in python
find the sum of all elements in an array in python
how to get distinct permutations of a set in python
how to get all combinations of a set in python
how to get the power set of a set in python
find the median of all elements in an array in python
define a function that takes a list of numbers as an argument and returns the sum of the numbers in the list. in python
find the largest number in the following list of numbers: [1, 3, 4, 2, 5] in python

related categories

python
arrays
average
sum
len

gistlibby LogSnag