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  
 
 [ 2 post ] 

 Relevant Pages 

1. Beginner's J questions, vol. 3

2. Beginner's 'enum' question

3. JS-EAI with *JS*-callback

4. js.exception 3279.js

5. Sorry it's beginner's question..

6. TK beginners question - how to 'beep'

7. Forth Dimensions: Vol 1 #1 - Vol 13 #6

8. Beginner's J questions, vol. 7 (zero-length arguments)

9. Beginner's J questions, vol. 8 (miscellaneous details)

10. Beginner's J questions, vol. 6 (ranks again)

11. Beginner's J question, vol. 5 (ranks continued)

12. Beginner's J question #12 - locales

 

 
Powered by phpBB® Forum Software