Relating to [this answer](https://stackoverflow.com/a/51029521/2431885), is there a fast way to compute medians over an array that has groups with an ***unequal*** number of elements?

E.g.:

```
data =  [1.00, 1.05, 1.30, 1.20, 1.06, 1.54, 1.33, 1.87, 1.67, ... ]
index = [0,    0,    1,    1,    1,    1,    2,    3,    3,    ... ]

```

And then I want to compute the difference between the number and the median per group (e.g. median of group `0` is `1.025` so the first result is `1.00 - 1.025 = -0.025`). So for the array above, the results would appear as:

```
result = [-0.025, 0.025, 0.05, -0.05, -0.19, 0.29, 0.00, 0.10, -0.10, ...]

```

Since `np.median.reduceat` doesn't exist (yet), is there another fast way to achieve this? My array will contain millions of rows so speed is crucial!

Indices can be assumed to be contiguous and ordered (it's easy to transform them if they aren't).

---

Example data for performance comparisons:
-----------------------------------------

```
import numpy as np

np.random.seed(0)
rows = 10000
cols = 500
ngroup = 100

# Create random data and groups (unique per column)
data = np.random.rand(rows,cols)
groups = np.random.randint(ngroup, size=(rows,cols)) + 10*np.tile(np.arange(cols),(rows,1))

# Flatten
data = data.ravel()
groups = groups.ravel()

# Sort by group
idx_sort = groups.argsort()
data = data[idx_sort]
groups = groups[idx_sort]

```