Reputation: 340
I am converting some MatLab code to Python, and cannot solve why the results I am getting are different.
In MatLab, the mad
function on the input x = [1, 2, 4, 3, 7, 2, 1, 3, 2, 1]
yields a result of 1.32
. However, when using the equiv function in SciPy.Stats
, that is, median_abs_deviation
, I get a different result of 1.0
.
My code, exactly is:
Matlab:
x = [1, 2, 4, 3, 7, 2, 1, 3, 2, 1];
mdat = mad(x)
Python:
from scipy import stats
x = np.array([1, 2, 4, 3, 7, 2, 1, 3, 2, 1])
print(stats.median_abs_deviation(x))
Upvotes: 0
Views: 239
Reputation: 4782
The default in Matlab is to compute the mean absolute deviation. If you want the median absolute deviation, then the command is mad(x,1)
.
If you're interested in computing the mean absolute deviation in Python, see this post.
Upvotes: 1