nicolaspanel / numjs

Like NumPy, in JavaScript
MIT License
2.4k stars 184 forks source link

How to find INDEX of maximum value in 2d array? #126

Open JSR694 opened 2 years ago

JSR694 commented 2 years ago

Hi there,

How can I find the INDICES of the max value in an array?

E.g., if my array looks like this:

var arr = array([[[ 1],
                            [ 9]],
                          [[ 0],
                           [ 5]]], dtype=uint8)

I would like to find the indices of the value 9. In this case, that is 0, 1, 0.

In Numpy, I would stack that array with a 2x2x2 meshgrid, giving the row and column of each element. Then, if I find the maximum element in arr[:,:,0], I just need to look at arr[:,:,1::] to get the row and column indices.

Thanks Jack