I have a 2D-array with zero values in each row.
[[5, 3, 2, 0, 0, 1, 6, 9, 11, 1, 4, 1],
[0, 0, 12, 0, 1, 0, 0, 2, 0, 30, 2, 2],
[120, 2, 10, 3, 0, 0, 2, 7, 9, 5, 0, 0]]
Is there a way to calculate the 0.75 quantile of each row by excluding the zero values in the calculation ?
For example, in the second row, only 6 non-zero values[12,1,2,30,2,2]
should be used in the calculation. I tried using np.quantile()
but it will includes all zero values in the calculation. It seems that Numpy don't have masked array np.ma
version of quantile()
also.