如何在朱莉娅产生对称矩阵?

发布于 2025-02-10 16:39:26 字数 86 浏览 3 评论 0原文

诸如RAND(M,N)之类的功能会生成M行和N列的随机矩阵。朱莉娅(Julia)中是否有任何功能可以生成对称任意维度的矩阵?

Functions like rand(m,n) generate a random matrix of m rows and n columns. Is there any function in Julia that can generate a Symmetric matrix of arbitrary dimensions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心房的律动 2025-02-17 16:39:26

您可以像在rand(M,N)中创建一个对称矩阵,但是您将无法分配给非二角形元素,因为这可能会破坏其对称性。因此,您应该先创建常规矩阵,然后转换为对称。

Symmetric(rand(0:9,5,5))
5×5 Symmetric{Int64, Matrix{Int64}}:
 5  2  1  4  1
 2  1  6  8  0
 1  6  2  0  6
 4  8  0  7  1
 1  0  6  1  4

You can create a symmetric matrix as you do in rand(m,n), but you will not be able to assign to non-diagonal elements as that might break its symmetry. So, you should create the general matrix first then convert to symmetric.

Symmetric(rand(0:9,5,5))
5×5 Symmetric{Int64, Matrix{Int64}}:
 5  2  1  4  1
 2  1  6  8  0
 1  6  2  0  6
 4  8  0  7  1
 1  0  6  1  4
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文