I have a matrix Mcontaining pairs (i.e. arrays of size 2). Given a pair p, how can I get a 2D matrix M'containing the result of the scalar product of p and each element of M?
(0, 0) (0, 1) 8 5
M = (1, 0) (1, 1) p = (2, 2) M' = 5 2
(2, 0) (2, 1) 4 1
M and p are defined :
M =. 3 2 2 $ 0 0 0 1 1 0 1 1 2 0 2 1
p =. 2 2
I have an implementation of scalar product in J :
sp =. +/ @: *: @: -
It works on pairs :
0 0 sp p
8
0 1 sp p
5
But not on the full matrix, because of bad length :
p sp M
|length error: sp
| p sp M
How should I deal with that ? This is probably easy for J geniuses, but I’m just a poor newbie.
Use
You want
sphere to read first-rank cells of M:so
sp"1will work on each cell (p sp 0 0,p sp 0 1, etc).sp(infinite rank) tries to apply sp once for the whole matrix M.Likewise
sp"2will applyspon second-rank cells of M:so
(the pairs:
p sp 2 2 $ 0 0 0 1,p sp 2 2 $ 1 0 1 1andp sp 2 2 $ 2 0 2 1)