I have an array that I want to convert to percentiles. For example, say I have a normally distributed array:
import numpy as np
import matplotlib.pyplot as plt
arr = np.random.normal(0, 1, 1000)
plt.hist(arr)
For each value in that array, I want to calculate the percentile of that value (e.g. 0 is the 50th percentile of the above distribution so 0 -> 0.5). The result should be uniformly distributed since each percentile should have equal weight.
I found np.percentile
but this function returns a value given an array and quantile and what I need is to return a quantile given an array and value.
Is there a relatively efficient way to do this?