Computing kurtosis from a numpy array?

I am trying to calculate the "excess" as well as other statistics from a numpy array. Calculating Min, Max, Average and Standard Deviation is easy, as I just did.

import arcpy arr = arcpy.RasterToNumPyArray(input_Raster) x = arr print 'Min =', x.min() print 'Max =', x.max() print 'Mean =', x.mean() print 'Standard Deviation =', x.std() 

What outputs:

 Min = 1.87895 Max = 16.8343 Mean = 8.03462 Standard Deviation = 1.52192 

But this method does not work for Kurtos! How i tried

 print 'Kurtosis =', x.kurtosis() 

And I get: AttributeError: the object 'numpy.ndarray' does not have the attribute 'kurtosis'

What would be the simplest code I could use to include in my own to calculate the result of kurtosis? Thank you

+5
source share
1 answer

Numpy is limited to fairly basic array operations, you need to contact him with the more educated Scipy brother to get more complex statistics functions ,

scipy.stats. kurtosis scipy.stats. kurtosis (a, axis = 0, fisher = True, bias = True)

Computes the excess (Fisher or Pearson) of the data set.

So, from scipy.stats import kurtosis , then kurtosis(x) .

In general, methods on Numpy arrays are limited only by basic operations ( max , min , etc.). A little more functionality is allocated from Numpy methods (for example, numpy.diff ), and even more from Scipy ( scipy.optimize.[whatever] scipy.signal.[whatever] scipy.optimize.[whatever] scipy.signal.[whatever] scipy.stats.[whatever] scipy.signal.[whatever] , scipy.stats.[whatever] )

+5
source

Source: https://habr.com/ru/post/1204713/


All Articles