method of finding the average value of

Asked 2 months ago, Updated 2 months ago, 2 views

How do I find the mean by referring to each element of the data below and how do I find the mean as an object?

import numpy as np
x = np.array ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
print('x[0]=',x[0],'x[10]=',x[10])

python

2022-09-30 13:58

1 Answers

import numpy as np

x = np.array ([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])

# calculate the average of the elements by dividing them by the number
sum = 0
for num in x:
    sum+=num
print(sum/len(x))

# Use average method as array object for numpy
print(np.average(x))


2022-09-30 13:58

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.