Singular value decomposition: Difference between revisions
Content added Content deleted
m (→{{header|Raku}}: superfluous) |
(Created Nim solution.) |
||
Line 301: | Line 301: | ||
-0.707107 0.707107 |
-0.707107 0.707107 |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{header|Nim}}== |
|||
{{libheader|arraymancer}} |
|||
<syntaxhighlight lang="Nim">import arraymancer, arraymancer/linear_algebra |
|||
var m = [[3, 0], [4, 5]].toTensor().asType(float) |
|||
let (u, s, vt) = m.svd() |
|||
# With "$", floats are displayed with 6 digits. |
|||
# So we use "pretty" to display 8 digits. |
|||
echo "U:" |
|||
echo u.pretty(8), '\n' |
|||
echo "Σ:" |
|||
echo s.pretty(8), '\n' |
|||
echo "V:" |
|||
echo vt.transpose().pretty(8) |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre>U: |
|||
Tensor[system.float] of shape "[2, 2]" on backend "Cpu" |
|||
|-0.31622777 -0.94868330| |
|||
|-0.94868330 0.31622777| |
|||
Σ: |
|||
Tensor[system.float] of shape "[2]" on backend "Cpu" |
|||
6.7082039 2.2360680 |
|||
V: |
|||
Tensor[system.float] of shape "[2, 2]" on backend "Cpu" |
|||
|-0.70710678 -0.70710678| |
|||
|-0.70710678 0.70710678| |
|||
</pre> |
|||
=={{header|Phix}}== |
=={{header|Phix}}== |