Python Example – Write a NumPy program to compute the weighted of a given array

Hits: 23 (Python Example for Beginners) Write a NumPy program to compute the weighted of a given array. Sample Solution: Python Code: import numpy as np x = np.arange(5) print(“nOriginal array:”) print(x) weights = np.arange(1, 6) r1 = np.average(x, weights=weights) r2 = (x*(weights/weights.sum())).sum() assert np.allclose(r1, r2) print(“nWeighted average of the said array:”) print(r1) … Continue reading Python Example – Write a NumPy program to compute the weighted of a given array

Copy and paste this URL into your WordPress site to embed

Copy and paste this code into your site to embed