Beginner's J questions, vol. 4
Author Message
Beginner's J questions, vol. 4

I was amazed by this behavior:

The function pe accepts a 3x3 matrix and returns a 3-element vector.
I have an Nx3x3 set of matrices, and I want to take the total of
the returns from pe, producing a 3-element vector.

So, I tried:

which surprised me by returning an N-element vector,
each of which was the sum of a row of the result of
(pe"2).  I was surprised because (pe"2) has shape (N,3),
so that +/ would, I thought, have produced shape 3.

I asked the interpreter what it thought, via:

g =. '+/ pe"2 y.'
G =. g : 20
G

and it spake:

which, sure enough, gives me my desired result.  What in
the world is the function of that ']'?

Henry Rich

Sun, 23 Mar 1997 22:41:44 GMT
Beginner's J questions, vol. 4
Henry Rich:
. I was amazed by this behavior:
.
. The function pe accepts a 3x3 matrix and returns a 3-element
. vector.  I have an Nx3x3 set of matrices, and I want to take the
. total of the returns from pe, producing a 3-element vector.
.
. So, I tried:
.

.
. which surprised me by returning an N-element vector, each of which
. was the sum of a row of the result of (pe"2).  I was surprised
. because (pe"2) has shape (N,3), so that +/ would, I thought, have
. produced shape 3.

pe"2 applies pe to the rank two subarrays of your matrix.  These
subarrays have the shape 3x3.  There are N of them.

. I asked the interpreter what it thought, via:
.
. g =. '+/ pe"2 y.'
. G =. g : 20
. G
.
. and it spake:
.

.
. which, sure enough, gives me my desired result.  What in the world
. is the function of that ']'?

] is an identify function.  It so happens that it has an infinite
rank.  Thus, +/ applies to the entire argument constructed by pe"2.

Another way of achieving this end would be to use

--
Raul D. Miller           n =: p*q             NB. 9<##:##:n [.large prime p, q

NB.  public e, n, y
x -: n&|&(*&y)^:d 1  NB. 1=(d*e)+.p*&<:q

Sun, 23 Mar 1997 23:22:57 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages