Python的 - 我如何才能找到一个下三角矩阵numpy的的方阵? (具有对称上三角) [英] Python — How can I find the square matrix of a lower triangular numpy matrix? (with a symmetrical upper triangle)

查看:2209
本文介绍了Python的 - 我如何才能找到一个下三角矩阵numpy的的方阵? (具有对称上三角)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我产生下三角矩阵,并且我想使用下三角矩阵中的值,以形成一个方阵,围绕对角线零对称以完成矩阵

I generated a lower triangular matrix, and I want to complete the matrix using the values in the lower triangular matrix to form a square matrix, symmetrical around the diagonal zeros.

lower_triangle = numpy.array([
[0,0,0,0],
[1,0,0,0],
[2,3,0,0],
[4,5,6,0]])

我想生成以下完整矩阵,保持零对角线:

I want to generate the following complete matrix, maintaining the zero diagonal:

complete_matrix = numpy.array([
[0, 1, 2, 4],
[1, 0, 3, 5],
[2, 3, 0, 6],
[4, 5, 6, 0]])

感谢。

推荐答案

您可以简单地把它添加到它的转置:

You can simply add it to its transpose:

>>> m
array([[0, 0, 0, 0],
       [1, 0, 0, 0],
       [2, 3, 0, 0],
       [4, 5, 6, 0]])
>>> m + m.T
array([[0, 1, 2, 4],
       [1, 0, 3, 5],
       [2, 3, 0, 6],
       [4, 5, 6, 0]])

这篇关于Python的 - 我如何才能找到一个下三角矩阵numpy的的方阵? (具有对称上三角)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆