np.mean
import numpy as np
import numpy as np
array1D = np.array([1,2,3,4,5])
print(f'Axis = -1 --> {array1D.mean(axis=-1)}')
print(f'Axis = 0 --> {array1D.mean(axis=0)}')
#### Output ####
Axis = -1 --> 3.0
Axis = 0 --> 3.0
array2D = np.array([[14, 17, 12, 33, 44],
[15, 6, 27, 8, 19],
[23, 2, 54, 1, 4]] )
print(f'Axis = -1 {array2D.mean(axis=-1)}')
print(f'Axis = 0 {array2D.mean(axis=0)}')
print(f'Axis = 1 {array2D.mean(axis=1)}')
#### Output ####
Axis = -1 [24. 15. 16.8]
Axis = 0 [17.33333333 8.33333333 31. 14. 22.33333333]
Axis = 1 [24. 15. 16.8]
# Online Python compiler (interpreter) to run Python online.
# Write Python 3 code in this online editor and run it.
import numpy as np
array3D = np.array([[[1, 2, 3, 4, 5],
[1, 2, 3, 4, 5],
[1, 2, 3, 4, 5]],
[[1, 2, 3, 4, 5],
[1, 2, 3, 4, 5],
[1, 2, 3, 4, 5]]])
print(f'Axis = -1 --> {array3D.mean(axis=-1)}')
print(f'Axis = 0 --> {array3D.mean(axis=0)}')
print(f'Axis = 1 --> {array3D.mean(axis=1)}')
print(f'Axis = 2 --> {array3D.mean(axis=2)}')
#### Output ####
Axis = -1 --> [[3. 3. 3.]
[3. 3. 3.]]
Axis = 0 --> [[1. 2. 3. 4. 5.]
[1. 2. 3. 4. 5.]
[1. 2. 3. 4. 5.]]
Axis = 1 --> [[1. 2. 3. 4. 5.]
[1. 2. 3. 4. 5.]]
Axis = 2 --> [[3. 3. 3.]
[3. 3. 3.]]
Fancy Falcon