Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!emory!gatech!udel!haven.umd.edu!socrates.umd.edu!socrates!rockwell From: rockwell@socrates.umd.edu (Raul Rockwell) Newsgroups: comp.lang.apl Subject: Re: Grade Down Columns of An Array Message-ID: Date: 21 Jun 91 13:05:48 GMT References: <33789@usc.edu> Sender: rockwell@socrates.umd.edu (Raul Rockwell) Organization: Traveller Lines: 63 In-Reply-To: ann@neuro.usc.edu's message of 21 Jun 91 03: 57:51 GMT Ann Simpson Chapin: 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 do not want to have to create an interactive function .. I am using APL Plus II on a 386 with plenty on memory and a math coprocessor..... Well, if you were using J, I'd recommend something like \:~ "1 &.|: array But since you're not, I'll try and describe a way to do this in vanilla APL. Basically, you coerce the array to a vector, sort the vector in a way which preserves the original column order, then reshape back to the original shape. First off, you'll need the array in vector form. You'll want all members of a single column adjacent to each other, so you need to transpose the array before you ravel it. I'm going to give each sentence twice -- once in psuedo-apl puns, and once in J. vec <- , (\) array vec =. , |: array Second off, you'll need to grade the array. You want the grade to preserve the original column ordering, so you need to normalize the array, and add numbers to force the proper static ordering. normalized <- /|\ /|\ array normalized =. /: /: array colHorder <- - (R vec) x (R array)[0] / i (R array)[1] col_order =. - (# vec) * (0{$array) # i. 1{$array grade <- \|/ colHorder + normalized grade =. \: col_order + normalized Finally, you need to restore the original shape of the array. Note that you need to do a transpose as well, which means that you need to reshape using transposed dimensions. (I'll just reverse the dimensions here). sorted <- (\) ( (|) R array)R vec[grade] sorted =. |: ( |. $ array)$ grade{vec voila. As an aside, I haven't tested this code yet, but the basic concept is sound. I hope you can read it. Also note that I've assumed origin 0 for the APL session -- I trust conversion to origin 1 is obvious, if that is desired. puns used here: <- assignment (\) transpose (|) rotate R rho H delta x times -- Raul