0

The simple example of the problem is: $Ax = b$

In my case:

enter image description here

Any idea/suggestion is highly appreciated.

SuperKogito
  • 2,998
  • 3
  • 16
  • 37
nero_bin
  • 65
  • 5
  • Are all the 2d's the same shape? Can they form a 3d array? – hpaulj May 26 '19 at 19:13
  • Yes, all the matrix elements are square with same shape. I'm thinking of making a big square matrix out of these 2D matrix elements and then presenting these b elements to single array. And then use linalg.solve to get single X vector which is then separated into each X_i. Please let me know, if this approach is correct. Or there is some other way to do it around more effectively. – nero_bin May 26 '19 at 19:20
  • Simplest would be to stack all of the matrices into one matrix - same with the right hand side `b` vector and solve it that way. – rayryeng May 26 '19 at 20:25

1 Answers1

2

As long as the dimensions conform, A is actually "just" a matrix, even if it is built out of smaller matrices. Here's a relatively general example showing how the dimensions must go:

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)
chthonicdaemon
  • 19,180
  • 2
  • 52
  • 66