In J, I can update a subset of an array in place according to some predicate, for example:
y (k}~) |. y {~ k =. I. '123' e.~ y =. '[1.2.3]'
[3.2.1]
I understand that I can name a union here, but is there a more elegant way to do this in the first place? 123is just an example. What I want to do, in particular, is:
- get array of indices into array (
k) - retrieve array elements at these indices into a new array
- converts this array to a new array with the same type and shape
- return the values of the new array to the slots.
In addition, it is important that the verb work with the array as a whole, because basically I want to rearrange and convert the subarrays into place. (Therefore, |.in the example.)
Is there an easier way to do this?