After
Matrix
11 9 0
10 1 0
With Thanks
Perhaps you mean
11 -9 0
11 1 0
Martin
"smandula" <sman...@idirect.com> wrote in message
news:c4d2ee9f-b160-4181...@d27g2000prf.googlegroups.com...
(<negative>2 -/Matrix),0
- Veli-Matti
( (0 1 {drop}Matrix) - (0 {neg}1{drop}Matrix) ),0
or
({rho}Matrix){take} (0 1 {drop}Matrix) - (0 {neg}1{drop}Matrix
"smandula" <sman...@idirect.com> wrote in message
news:c8c67db2-a0f3-4bb6...@d21g2000prf.googlegroups.com...
Should your after matrix look like:?
11 -9 0
11 1 0
If so, the way it's done in WinAPL is (¯2-/T),0
Lance
why does negative 2 work? it's bad syntax to me. (high minus
2)matrix???? negation 2 also works.
In this case the reduce operator has two operands, and it's called
n-wise reduction, ie. the operand function (right operand) is used
for each sub-array whose length is <absolute>left operand. If the
left operand is negative, the sub-array is reversed before the right
operand function is called.
The axis of the operation may be given in braces after the operand,
ie. (-2)/[2]MAT means the second axis (rowwise).
The default axis for reduction is the last axis, so we don't need
the axis definition in the example.
The example matrix has two sub-matrices which both have two
columns (because of the -2 operand):
1 12 and 12 3
24 35 35 36
those matrices are reversed, because the left operand was negative
(quite handy with subtraction):
12 1 and 3 12
35 24 36 35
then the right operand function takes place
(12-1) and (3-12)
(35-24) (36-35)
and at last we get the result by joining the columns:
11 -9
11 1
NB. the result has one column less than the original, so we have to
add extra zero to get the same shape as the original matrix has
Hopefully this lightens the idea.
-wm
If you find the negative left operand counter-intuitive, you could
just commute the subtract function. These are equivalent:
¯2 -/↑(1 12 3 )(24 35 36)
2(-⍨)/↑(1 12 3 )(24 35 36)
(for non-Unicoders)
¯2 - /{take}(1 12 3 )(24 35 36)
2(-{commute})/{take}(1 12 3 )(24 35 36)
"Negation also works". Yes, by reversing the sign of all the results.
Same answer, but quite different mechanism from using ¯2.
SJT
(-n)f/⍵ ←→ n f⍨/⍵ ⍝ Stephen's equivalence
But beware, beyond the special case of n=2 the equivalence only holds
for associative functions.
¯2-/1 9 2 8 3 7 4 6 5
8 ¯7 6 ¯5 4 ¯3 2 ¯1
2-⍨/1 9 2 8 3 7 4 6 5
8 ¯7 6 ¯5 4 ¯3 2 ¯1
¯3-/1 9 2 8 3 7 4 6 5
¯6 15 ¯3 12 0 9 3
3-⍨/1 9 2 8 3 7 4 6 5
¯8 ¯3 ¯7 ¯4 ¯6 ¯5 ¯5
Personally, I should have thought neg-n-wise reduction would have been
more usefully defined such that the equivalence does hold for all
functions rather than the conceptual oddity of the reversal of sub-
arrays.
btw. The number to the left is not, strictly speaking, another operand
to reduction but the left argument to the derived function (f/).
Touché!
-wm