Skip to content
Advertisement

Numpy find maximum tuple in array of windows

I’m starting our with list of tuples (each tuple is an (X,Y)). My end result is I want to find the maximum Y-value within EACH window/bin of length 4 using numpy.

JavaScript

Expected output I want from each window/blocks using max y-value is below. Alternatively format could be regular list of tuples, doesn’t strictly need to be numpy array:

JavaScript

Advertisement

Answer

Here is a vectorized (and probably fastest) approach:

JavaScript

You basically use a array (non-structured) version of your structured array by view and find argmax of Y along axis=1. Then use those indices to filter the tuples from your original array arr.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement