I'm new to APL and I would like to find the position of an element(s) within a vector. For example, if I create a vector of 50 random numbers:
lst ← 50 ? 100
How can I find the positions of 91 assuming it occurs 3 times in the vector?
Thanks.
I'm not an expert, but a simple way is to just select the elements from ⍳ 100 where the corresponding element in lst is 91
(lst=91)/⍳100
With Dyalog 16.0, you can use the new monadic function ⍸ "Where".
⍸lst=91
lst=91 gives a vector of 0s and 1s. Applying ⍸ on this gives the locations of all the 1s. This also works if lst is a matrix.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With