Element-wise operations: Difference between revisions

m
{{out}}
m (→‎{{header|REXX}}: removed OVERFLOW from PRE html tags.)
m ({{out}})
Line 41:
end Scalar_Ops;</lang>
 
{{out}}
The output is:
 
<pre> Initial M=((1,2,3),(4,5,6),(7,8,9))
M+2=((3,4,5),(6,7,8),(9,10,11))
Line 179 ⟶ 178:
))
)</lang>
{{out}}
Output:
<pre>
((17.00, 21.00, 23.00),
Line 268 ⟶ 267:
NEXT
= a$ + "]"</lang>
{{out}}
'''Output:'''
<pre>
[[7, 8, 7][4, 0, 9]] + [[4, 5, 1][6, 2, 1]] = [[11, 13, 8][10, 2, 10]]
Line 606 ⟶ 605:
==Icon and {{header|Unicon}}==
 
This is a Unicon-specific solution solely because of the use of the <tt>[: ... :]</tt> operator. It would
It would be easy to replace this with another construct to produce a version that works in both languages.
The output flattens each displayed matrix onto a single line to save space here.
<lang unicon>procedure main()
Line 647 ⟶ 646:
end</lang>
 
{{out}}
Output:
<pre>
->ewo
Line 943 ⟶ 942:
_E</lang>
 
{{out}}
Output:
<pre>a 1 2 3 4 5 6 7 8 9
a OP a
Line 981 ⟶ 980:
msay @a «*» 2;
msay @a «/» 2;</lang>
{{out}}
Output:
<pre>[2, 4, 6]
[8, 10, 12]
Line 1,050 ⟶ 1,049:
(println (elementWiseMatrix / M M))
(println (elementWiseMatrix ** M M)) )</pre>
{{out}}
Output:
<pre>((17 21 23) (27 29 33) (39 41 47))
((-3 1 3) (7 9 13) (19 21 27))
Line 1,190 ⟶ 1,189:
</lang>
 
{{outputout}}
 
<pre>
(array #[#[1 3] #[2 4]])
Line 1,236 ⟶ 1,234:
mat#: w=words(@); do j=1 for w; !.j=word(@,j); end; return
mat@: @=!.1; do j=2 to w; @=@ !.j; end; return @</lang>
{{out}}
'''output'''
<pre style="height:55ex">
──M matrix──
Line 1,307 ⟶ 1,305:
mat#: w=words(@); do j=1 for w; !.j=word(@,j); end; return
mat@: @=!.1; do j=2 to w; @=@ !.j; end; return @</lang>
{{out}}
'''output'''
<pre style="height:55ex">
──M matrix──
Line 1,380 ⟶ 1,378:
puts "m1 %-4s m2 = %s" % [op, m1.element_wise(op, m2)]
end</lang>
{{Outputout}}
<pre>
m1: Matrix[[3, 1, 4], [1, 5, 9]]
Anonymous user