Where can I find mad (mean absolute deviation) in scipy?

前端 未结 10 1576
故里飘歌
故里飘歌 2020-12-23 16:36

It seems scipy once provided a function mad to calculate the mean absolute deviation for a set of numbers:

http://projects.scipy.org/scipy/browser/trunk

10条回答
  •  萌比男神i
    2020-12-23 17:37

    Using numpy only:

    def meanDeviation(numpyArray):
        mean = np.mean(numpyArray)
        f = lambda x: abs(x - mean)
        vf = np.vectorize(f)
        return (np.add.reduce(vf(numpyArray))) / len(numpyArray)
    

提交回复
热议问题