9951 explained code solutions for 126 technologies


python-numpyGet array mean along an axis


import numpy as np
arr = np.array([[1, 2], [3, 4]])
mean = np.mean(arr,axis=1)ctrl + c
import numpy as np

load Numpy module for Python

np.array

declare Numpy array

[[1, 2], [3, 4]]

sample matrix data

np.mean

returns given array mean

axis=1

returns array of mean values along horizontal axis (use axis=0 to get mean values along vertical axis)