import numpy as np
arr1 = np.array([1,2,3, 2,4,6, 1,2,12, 0,-12,6])
print("Original array:")
print(arr1)
result = np.mean(arr1.reshape(-1, 3), axis=1)
print("Average of every consecutive triplet of elements of the said array:")
print(result)
Sample Output:
Original array:
[ 1 2 3 2 4 6 1 2 12 0 -12 6]
Average of every consecutive triplet of elements of the said array:
[ 2. 4. 5. -2.]
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer