Newsgroups: comp.lang.apl
Path: watmath!ljdickey
From: ljdickey@watmath.waterloo.edu (L.J.Dickey)
Subject: Re: Grade Down Columns of An Array
Message-ID: <1991Jun21.060649.919@watmath.waterloo.edu>
Organization: University of Waterloo
References: <33789@usc.edu>
Date: Fri, 21 Jun 1991 06:06:49 GMT
Lines: 80

In article <33789@usc.edu> ann@neuro.usc.edu (Ann Simpson Chapin) writes:
>Does anyone know how to grade down the columns of an array (rank 2) so that
>each column of the array is graded down as if it is a separate vector?

I have a solution to this problem.

>I do not want to have to create an interative function, and I also do not
>want to have to create separate vectors from each column, grade down each
>vector, and then reconcatenate the vectors into the original array.

Yeah, that would be a pain.

>I have received several suggestions from various sources about creating
>nested indicies into the array to solve the problem, but everyone I know
>that has tried to solve this problem in a noniterative fashion has not 
>been able to.  If you can do this, please include the steps in your 
>response.

Here are the steps in my solution, straight from a session script:

   NB: =: '0 0$0' : 'x.'
   shape =. 4 5
   m =. (($?~)*/) shape       NB: 'Deal me a matrix.'
   m                          NB: 'What did I get?'
 6  7  1  2 18
13  4 15  3  0
16 19 12 17 14
 8 10 11  5  9
   r =. (\:"1)&.|:m           NB: 'Grade down each row under transpose.'
   c =. ($m)$i.}.$m           NB: 'Plain column selectors.'
   ( <"1 r,"_2 c ){m          NB: 'The desired result.'
16 19 15 17 18
13 10 12  5 14
 8  7 11  3  9
 6  4  1  2  0
   ( <"1 r,"_2 c )            NB: 'The indices.'
+---+---+---+---+---+
|2 0|2 1|1 2|2 3|0 4|
+---+---+---+---+---+
|1 0|3 1|2 2|3 3|2 4|
+---+---+---+---+---+
|3 0|0 1|3 2|1 3|3 4|
+---+---+---+---+---+
|0 0|1 1|0 2|0 3|1 4|
+---+---+---+---+---+

Comments:

The thing that makes this relatively easy in J is the way
the rank operator can be used to great advantage.
The first place this happens is in the expression 
        \:"1
which means grade down each row.  I used this on each row of the
transpose, and then transposed the result back to get "r".
This was the most interesting part for me.

The second most interesting part was discovering how to
put the row indices and column indices together to generate
the subscripts used to select from the matrix.   For me, the
expression

   ( <"1 r,"_2 c ) 

was enlightening.

>           I am using APL Plus II on a 386 with plenty on memory and a 
>math coprocessor.....
>
>Thanks, Ann

I am using J, Version 3.2 on my Atari Mega ST2.

Thank you, Ann, for posting such an interesting question.  
I have learned a little more about J and the rank operator.

-- 
Prof L.J. Dickey, Faculty of Mathematics, U of Waterloo, Canada N2L 3G1
internet:       ljdickey@watmath.UWaterloo.ca	BITNET/EARN:	ljdickey@watdcs
obsolescent?:	ljdickey@watmath.waterloo.edu
UUCP:		ljdickey@watmath.UUCP	..!uunet!watmath!ljdickey
