In numpy, why is it ok to do matrix.mean(), but not ok to do matrix.median()?

C W tmrsg11 at gmail.com
Tue May 1 13:57:54 EDT 2018


Hello everyone,

In numpy, why is it ok to do matrix.mean(), but not ok to do
matrix.median()? To me, they are two of many summary statistics. So, why
median() is different?

Here's an example code,

import numpy as np
matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])

# find the mean
np.mean(matrix)      # ok
matrix.mean()          # ok

# find the median
np.median(matrixA)  # ok
matrix.median()        # throws error message


Also, why have two of the same thing: np.mean(matrix) and matrix.mean()?
When to use which one?

The documentation below looks almost identical! What am I missing here?
[1] Median documentation:
https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.median.html
[2] Mean documentation:
https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.mean.html


Thank you so much,

M



More information about the Python-list mailing list