Anonymous user
Matrix multiplication: Difference between revisions
→{{header|J}}: Add examples, elaborate on general inner product.
(added APL) |
(→{{header|J}}: Add examples, elaborate on general inner product.) |
||
Line 503:
=={{header|J}}==
Matrix multiply in J is just <tt>+/ .*</tt>. For example:
A =: ^/~>:i. 4 NB. Same A as in other examples (1 1 1 1, 2 4 8 16, 3 9 27 81,:4 16 64 256)
equals the leading dimension of array<tt> y</tt>). The notation is for a generalized inner product▼
B =: %.A NB. Matrix inverse of A
'6.2' 8!:2 A x B
1.00 0.00 0.00 0.00
0.00 1.00 0.00 0.00
0.00 0.00 1.00 0.00
0.00 0.00 0.00 1.00
▲
etc. ▼
The general inner product extends to multidimensional arrays, with the only requirement being that <tt> x </tt>and<tt> y </tt> to be conformable (trailing dimension of array<tt> x </tt> equals the leading dimension of array<tt> y</tt>). For example, the matrix multiplication of two dimensional arrays requires <tt>x</tt> must have the same numbers of rows as <tt>y</tt> has columns, as you would expect.
▲ x ~:/ .*. y NB. boolean inner product (<tt>~: </tt>is "not equal" (exclusive or) and<tt> *. </tt>is "and")
▲ x *./ .= y NB. which rows of x are the same as vector y?
▲ x + / .= y NB. number of places where each row of x equals vector y
▲etc.
=={{header|Java}}==
|