You are calling kurtosis on axis=0 by default (see docs), but it seems like you're trying to run it on the whole array. So you can try axis=None:
kurtosis(gray_img, axis=None)
Example:
im = np.random.randint(0,256,(5,5))
>>> im
array([[104, 125, 26, 194, 47],
[198, 46, 105, 38, 241],
[211, 115, 62, 196, 169],
[ 92, 184, 212, 100, 117],
[212, 35, 208, 52, 3]])
>>> kurtosis(im)
array([-1.78890733, -1.32154862, -1.66900354, -1.74522902, -1.30434102])
>>> kurtosis(im, axis=None)
-1.3968689968948007
[EDIT]: From your comments, you are trying to calculate skewness, not kurtosis. For this, use:
from scipy.stats import kurtosis,skew
skew(gray_img, axis=None)
In matlab, on the array above, your code (taken directly from your comments) gives:
im =
104 125 26 194 47
198 46 105 38 241
211 115 62 196 169
92 184 212 100 117
212 35 208 52 3
>> I2 = im2double(im);
>> s=skewness(I2(:))
s =
0.0118
In scipy, it gives:
>>> skew(im,axis=None)
0.011819746815198935
[Edit #2]: It seems MATLAB's default kurtosis definition is Pearson's, whereas Scipy's is Fisher's. +1 to scipy for being more flexible than MATLAB! So you can use:
kurtosis(im, None, fisher=False)
To get the same results:
# Scipy:
>>> kurtosis(im,None, fisher=False)
1.6031310031051993
# Matlab:
>> s=kurtosis(I2(:))
s =
1.6031