np.array average row
>>> a = np.array([[1, 2], [3, 4]])
>>> np.mean(a)
2.5
>>> np.mean(a, axis=0)
array([2., 3.])
>>> np.mean(a, axis=1)
array([1.5, 3.5])
np.array average row
>>> a = np.array([[1, 2], [3, 4]])
>>> np.mean(a)
2.5
>>> np.mean(a, axis=0)
array([2., 3.])
>>> np.mean(a, axis=1)
array([1.5, 3.5])
find average of list python
list = [15, 18, 2, 36, 12, 78, 5, 6, 9]
# for older versions of python
average_method_one = sum(list) / len(list)
# for python 2 convert len to a float to get float division
average_method_two = sum(list) / float(len(list))
# round answers using round() or ceil()
print(average_method_one)
print(average_method_two)
numpy average
import numpy as np
a = np.arange(6).reshape(3,2)
average = np.average(a)
python get average of list
#python3
def average(list):
result = sum(list) / len(list)
return result
list = [68,68,71,71,71,75,71,78,91,98,75,71,84]
print(average(list))
python find average of list
# A function that finds an average of a list of numbers
numbers = [1,2,3,4,5,6,7,889,102390143]
def find_average(number_list):
total = 0
for number in number_list:
total += number
average = total / len(number_list)
print("Your average is:", average)
find_average(numbers)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us