numpy 中的对称矩阵?
我希望在 python 中启动一个对称矩阵并用零填充它。
目前,我已经启动了一个已知维度的数组,但这不适合随后作为距离矩阵输入到 R 中。
numpy 中是否有任何“简单”方法来创建对称矩阵?
编辑
我应该澄清 - 创建“对称”矩阵很好。然而,我只对生成下三角形式感兴趣,即,
ar = numpy.zeros((3, 3))
array([[ 0., 0., 0.],
[ 0., 0., 0.],
[ 0., 0., 0.]])
我想:
array([[ 0],
[ 0, 0 ],
[ 0., 0., 0.]])
这可能吗?
I wish to initiate a symmetric matrix in python and populate it with zeros.
At the moment, I have initiated an array of known dimensions but this is unsuitable for subsequent input into R as a distance matrix.
Are there any 'simple' methods in numpy to create a symmetric matrix?
Edit
I should clarify - creating the 'symmetric' matrix is fine. However I am interested in only generating the lower triangular form, ie.,
ar = numpy.zeros((3, 3))
array([[ 0., 0., 0.],
[ 0., 0., 0.],
[ 0., 0., 0.]])
I want:
array([[ 0],
[ 0, 0 ],
[ 0., 0., 0.]])
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为尝试使用这种三角形阵列是不可行的。
因此,这里是(平方)成对欧几里得距离的简单实现:
就性能而言,很难击败它(在 Python 级别)。不使用这种方法的主要优点是什么?
I don't think it's feasible to try work with that kind of triangular arrays.
So here is for example a straightforward implementation of (squared) pairwise Euclidean distances:
For performance wise it's hard to beat it (in Python level). What would be the main advantage of not using this approach?