Newsgroups: comp.lang.apl
Path: watmath!watserv1!72740.1026@compuserve.com
From: Bob Hendricks <72740.1026@CompuServe.COM>
Subject: Re: J? on Matrix Trans
Message-ID: <920212212548_72740.1026_EHE46-1@CompuServe.COM>
Sender: hesse@watserv1.waterloo.edu (BJ Cameron - DCS)
Organization: University of Waterloo
Date: Wed, 12 Feb 1992 21:25:49 GMT
Lines: 62

This is in answer to the mail by Bin Li questioning how to do left shifts
with 0 fill on rows of matrices using J code.

      a=. 1+i. 3 3
      a
1 2 3
4 5 6
7 8 9

      NB. Shift left with 0 fill on right using !. (customize).

      shift=. |.!.0
      shiftrows =. shift "1
      1 shiftrows a
2 3 0
5 6 0
8 9 0

      NB. Shifting rows with 0 fill doesn't work.  Why?

      shiftrows =. |."1
      1 shiftrows a
2 3 1
5 6 4
8 9 7
      1 shiftrows !.0 a     NB. Shouldn't this work?
domain error

      NB. The code fragment given in the referenced note from Bin Li
      NB. would not work on my release of J 4.0.  The code produces:

      |: 0 (2)}|: 1|."1 a
2 3 1
5 6 4
0 9 7

      NB. After transpose, the 8 is in index position 2 and it is
      NB. replaced by a 0.  His result was:

      NB.     |: 0 (2)}|: 1|."1 a
      NB. 2 3 0
      NB. 5 6 0
      NB. 8 9 0

      NB. Maybe the definition of } (amend) has be revised.

      NB. Note that to make } (amend) work, you could do the following:

      u=. {:"1 @ i. @ $ @ ]
      0 u a
2 5 8
      0 u} a
1 2 0
4 5 0
7 8 0
      0 u} 1 shiftrows a
2 3 0
5 6 0
8 9 0

Bob Hendricks

