求解线性方程,其中每个矩阵元素本身是矩阵(2D),每个变量是1D向量

时间:2019-05-26 18:09:22

标签: python numpy scipy linear-equation

该问题的简单示例是: $Ax = b$

就我而言:

enter image description here

任何想法/建议都受到高度赞赏。

1 个答案:

答案 0 :(得分:2)

只要维数一致,即使A是由较小的矩阵构建而成的,它实际上也是“仅”一个矩阵。这是一个比较普通的示例,显示了尺寸必须如何变化:

import numpy
import numpy.linalg

l, m, n, k = 2, 3, 4, 5

# if these are known, obviously just define them here.
A11 = numpy.random.random((l, m))
A12 = numpy.random.random((l, n))
A21 = numpy.random.random((k, m))
A22 = numpy.random.random((k, n))
x1 = numpy.random.random((m,))
x2 = numpy.random.random((n,))

A = numpy.bmat([[A11, A12], 
                [A21, A22]])
x = numpy.concatenate([x1, x2])

b = numpy.linalg.solve(A, x)