I have two equal-length 1D numpy arrays, id
and data
, where id
is a sequence of repeating, ordered integers that define sub-windows on data
. For example:
id data
1 2
1 7
1 3
2 8
2 9
2 10
3 1
3 -10
I would like to aggregate data
by grouping on id
and taking either the max or the min.
In SQL, this would be a typical aggregation query like SELECT MAX(data) FROM tablename GROUP BY id ORDER BY id
.
Is there a way I can avoid Python loops and do this in a vectorized manner?