Skip to content
Advertisement

Iterate over 2D numpy array to find corresponding maximum values

I have a set of data as such:

JavaScript

I need to iterate over each value in the first column, find the corresponding maximum value in the second column and then store in a new array (or delete the other values from this array). For this example the final output would therefore be:

JavaScript

I have managed to write a piece of code that will do this for a specific column value, but can’t work out how to turn it into a loop to do the whole array:

Create an array to store values in:

JavaScript

Find the maximum value for each column value (this is where I need the help!):

JavaScript

Thanks in advance for any help you can give!!!

Advertisement

Answer

The numpy method for this would be:

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