Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating kurtosis from a numpy array?

I am trying to calculate 'kurtosis', as well as other statistics from a numpy array. Calculating Min, Max, Mean and Standard Deviation are easy as I've just done.

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()

Which outputs:

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

But this method doesn't work for Kurtosis! As I've tried

print 'Kurtosis =', x.kurtosis()

And I get: AttributeError: 'numpy.ndarray' object has no attribute 'kurtosis'

What would be the simplest code I could use to incorporate into my own to calculate a kurtosis result? Thanks.

like image 356
Student2014 Avatar asked Oct 15 '14 07:10

Student2014


1 Answers

Numpy is restricted to fairly basic array operations, you need to reach out to it's more educated brother, Scipy, to get more advanced stats functions.

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

Computes the kurtosis (Fisher or Pearson) of a dataset.

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

In general, the methods on Numpy arrays are restricted to only the most basic operations (max, min, etc.). Slightly more functionality is eked out of Numpy methods (e.g. numpy.diff), and more still from Scipy (scipy.optimize.[whatever] scipy.signal.[whatever], scipy.stats.[whatever])

like image 131
Nick T Avatar answered Oct 08 '22 12:10

Nick T