On Sun, May 10, 2009 at 11:35 PM, John Randall
<[email protected]> wrote:
> I want to swap two array elements, and I am trying to do it by
> transposing indices.  So far I have come up with
>
> swapindices=:}: @: C. @: (; ~.)
>
>   10 swapindices 3 5
> 0 1 2 5 4 3 6 7 8 9
>   10 swapindices 3 9
> 0 1 2 9 4 5 6 7 8 3
>   10 swapindices 3 3
> 0 1 2 3 4 5 6 7 8 9
>
> Is this a sensible approach, or I am missing something much simpler?

It is sensible, but there are others, eg.

   (<1 2) C. 'wierd'
weird
   1 2 |.@:{`[`]} 'wierd'
weird

Ambrus
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to