Write a NumPy program to create a new array which is the average of every consecutive triplet of elements of a given array
- برمجة بايثون
- 2021-09-13
- mhanasmh00489829403
الأجوبة
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.]
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال