12 ms·
It's not sort. In Kap, sort down is ∨. The grade functions returns a sorted index. Basically ⍒ 3 1 2 1 1 returns 0 2 1 3 4. So yes, it performs a sort, but it r
by lokedhs 3y ago
It's not sort. In Kap, sort down is ∨. The grade functions returns a sorted index. Basically ⍒ 3 1 2 1 1 returns 0 2 1 3 4. So yes, it performs a sort, but it returns an index that can be used to later look up the respective elements.
You can read more about it here if you're interested: https://www.aplwiki.com/wiki/Grade https://www.aplwiki.com/wiki/Grade
And here's a silly example where a random array is created, then an array lookup is performed on the sorted indexes:
https://kapdemo.dhsdevelopments.com/clientweb2/#a%20%E2%86%90%20%3F20%E2%8D%B4100%20%20%20%20%20%20%20%E2%8D%9D%20Create%20a%20random%20array%20of%2020%20numbers%20between%200%20and%2099%0Ab%20%E2%86%90%20a%5B%E2%8D%8Ba%5D%20%20%20%20%20%20%20%20%20%E2%8D%9D%20Look%20up%20values%20in%20a%20based%20on%20the%20graded%20index%0An%20%E2%86%90%20(%3Ca)%20%E2%8D%AA%20b%20%20%20%20%20%20%E2%8D%9D%20Increase%20the%20rank%20of%20a%20(turning%20it%20into%20a%202-dimensional%20array)%20and%20attach%20b%20below%20it%2C%20creating%20a%202-by-20%20array%0Achart%3Abar%20n%20%20%20%20%20%20%20%E2%8D%9D%20Display%20the%20result%20in%20a%20bar%20chart%0An%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%E2%8D%9D%20Return%20n%20so%20it's%20printed%20after%20the%20chart https://kapdemo.dhsdevelopments.com/clientweb2/#a%20%E2%86%9...
- amluto 3y agoThat’s why I said argsort :) https://numpy.org/doc/stable/reference/generated/numpy.argsort.html https://numpy.org/doc/stable/reference/generated/numpy.argso... I assume this name derives from argmin and argmax, which go back at least to MATLAB. But MATLAB has sort returning indices too.