Matrix multiplication: Difference between revisions
Content added Content deleted
m (→{{header|BASIC}}: lang tag) |
|||
Line 2,671: | Line 2,671: | ||
Here we use Z with an "op" of <tt>*</tt>, which is a zip with multiply. This, along with the <tt>[+]</tt> reduction operator, replaces the inner loop. We chose to split the outer X loop back into two loops to make it convenient to collect each subarray value in <tt>[...]</tt>. It just collects all the returned values from the inner loop and makes an array of them. The outer loop simply returns the outer array. |
Here we use Z with an "op" of <tt>*</tt>, which is a zip with multiply. This, along with the <tt>[+]</tt> reduction operator, replaces the inner loop. We chose to split the outer X loop back into two loops to make it convenient to collect each subarray value in <tt>[...]</tt>. It just collects all the returned values from the inner loop and makes an array of them. The outer loop simply returns the outer array. |
||
=={{header|Phix}}== |
|||
Copy of [[Matrix_multiplication#Euphoria|Euphoria]] |
|||
<lang Phix>function matrix_mul(sequence a, sequence b) |
|||
sequence c |
|||
if length(a[1]) != length(b) then |
|||
return 0 |
|||
else |
|||
c = repeat(repeat(0,length(b[1])),length(a)) |
|||
for i=1 to length(a) do |
|||
for j=1 to length(b[1]) do |
|||
for k=1 to length(a[1]) do |
|||
c[i][j] += a[i][k]*b[k][j] |
|||
end for |
|||
end for |
|||
end for |
|||
return c |
|||
end if |
|||
end function</lang> |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |