title: How can I generate a large ndarray with the structure of a smaller one in Numpy?
body: <p>I'm trying to construct a large matrix with the structure of a smaller one in python using numpy ndarrays, where the dimensions are dynamic variables within my problem.</p>
  <p>For a simple test case, take the following code:</p>
  <pre><code>A = np.ones((2, 2))
  B = np.zeros((2, 2))
  
  matrix_structure = np.diag(np.ones(dimension-1), 1) + np.diag(np.ones(dimension-1), -1)
  
  </code></pre>
  <p>For a matrix dimension of 4, the matrix structure might look like the following:</p>
  <pre><code>[ 0 1 0 0 ]
  [ 1 0 1 0 ]
  [ 0 1 0 1 ]
  [ 0 0 1 0 ]
  </code></pre>
  <p>with the desired final matrix being something like:</p>
  <pre><code>[ B A B B ]
  [ A B A B ]
  [ B A B A ]
  [ B B A B ]
  </code></pre>
  <p>where A and B are the smaller submatrices.</p>
  <p>I'm stuck on how to make that step - the function np.block() would do what I want, if I could figure out how to pass an appropriate array.</p>
  <p>Is there a way to generate and then pass a multi-dimensional list of variable names, which then would pull the appropriate variable? Or am I just barking up the wrong tree here?</p>
  <p>Edit:</p>
  <p>Just for clarification, the final matrix (if A and B  are 2x2) would look something like:</p>
  <pre><code>[ 0 0 1 1 0 0 0 0 ]
  [ 0 0 1 1 0 0 0 0 ]
  [ 1 1 0 0 1 1 0 0 ]
  [ 1 1 0 0 1 1 0 0 ]
  [ 0 0 1 1 0 0 1 1 ]
  [ 0 0 1 1 0 0 1 1 ]
  [ 0 0 0 0 1 1 0 0 ]
  [ 0 0 0 0 1 1 0 0 ]
  
  </code></pre>
  <p>ie. the same structure, but composed of the smaller submatrices. The simple ones/zeros submatrices are just being used for illustration purposes.</p>