Hello.

I'd like to find the best implementation for shallow transpose, a
monad that swaps the first two axis of a noun.

If this verb is given a noun y of rank at least two, it should return
a noun z that has the same rank, the dimensions of z are the same as
those of y except that the first two are swapped, and an atom elemet
of z can be found by indexing y with the same indices except with the
first two indices swapped.  I don't define what exactly should happen
if called with a noun of rank less than two.  Below are a few model
implementations for this verb, and some examples.

What implementation (out of these or any other you would suggest) do
you favor?  (Also, why doesn't the builtin (|:) already do this in the
monadic case?  Wouldn't that be more versatile than the current
behaviour, especially if you can also rank it?)

   trans =: |:&.(<"_2)
   trans1 =: [:,./,:"_2
   trans2 =: |:~0,2}.i.@:#@:$
   trans3 =: {"_ _1"0 _~[:i.1{$
   trans4 =: [:|:_2|:|:
   trans i. 2 3
0 3
1 4
2 5
   $ trans i. 2 3
3 2
   trans i. 2 3 4
 0  1  2  3
12 13 14 15

 4  5  6  7
16 17 18 19

 8  9 10 11
20 21 22 23
   $ trans i. 2 3 4
3 2 4
   $ trans i. 2 3 4 5
3 2 4 5

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

Reply via email to