python numpy ndarray element-wise mean python numpy ndarray element-wise mean numpy numpy

python numpy ndarray element-wise mean


You can just use np.mean directly:

>>> np.mean([a, b, c], axis=0)array([ 30.,  20.,  30.])


Pandas DataFrames have built in operations to get column and row means. The following code may help you:

import pandas and numpyimport pandas as pdimport numpy as np# Define a DataFramedf = pd.DataFrame([np.arange(1,5), np.arange(6,10),np.arange(11,15)])# Get column means by adding the '.mean' argument# to the name of your pandas Data Frame# and specifying the axiscolumn_means = df.mean(axis = 0)'''print(column_means)0    6.01    7.02    8.03    9.0dtype: float64'''   # Get row means by adding the '.mean' argument# to the name of your pandas Data Frame# and specifying the axisrow_means = df.mean(axis = 1)'''print(row_means)0     2.51     7.52    12.5dtype: float64'''