6. Write a Python Numpy program to calculate weight average of the given array in the following output.
The output is:
Expected Answer:
Initial array: [1 2 3 4 5]
Weights: [2 3 4 5 6]
Weighted average of the array: 3.5
Sample Answer:
import numpy as np
a = np.arange(1, 6)
print("Initial array:", a)
weights = np.arange(2, 7)
print("\nWeights: ", weights)
r1 = np.average(a, weights=weights)
print("\nWeighted average of the array:", r1)
More Exercises:
Python String ExercisesMore Numpy Exercises:
Numpy String ExercisesMore Pandas Exercises:
Pandas Series ExercisesMore Tutorials:
Python Installation - Linux (Ubuntu)