Let's say I have a heatmap of probability density function as a numpy ndarray(m,n)
. Is there a function that automatically computes mean treating this matrix as probability density? I can't seem to find a function that would automatically do that.
Of course an easy solution would be to create a weighted average with weights equal to indices of the array, but seems like there should be a built-in function that would just do that.
Clasification:
Say my array is heatmap = [[0,0,0,1],[0,0,1,0],[0,0,1.5,0],[0,0,0,0]]
.
No if we assume that this is not normalized probability you can calculate mean and other properties of the probability density.
For example mean in x direction would be
xx = np.arange(0,heatmap.shape[1],1)
weights = np.tile(xx,(heatmap.shape[0],1))
mean_x = np.average(weights, weights = heatmap_avg_left)
I'm just looking for a function in numpy or scipy that would do this and other probability properties automatically