title: Creating numpy array of matrices
body: <p>I am trying to create a multi-dimensional numpy array where the data type is a matrix. So, I would like to be able to store a 3x3 numpy matrices into a multi-dimensional array. For example, I would like to create a numpy array of size 100 x 100 x 100, so when I refer to an index like:</p>
  
  <pre><code>x [10, 10, 10] &lt;- should return a 3x3 numpy matrix
  </code></pre>
  
  <p>I can do something like:</p>
  
  <pre><code>x = np.array((100, 100, 100), np.matrix)
  </code></pre>
  
  <p>However, I am not sure how to define the size of the matrix in this case. Another option is to do something like:</p>
  
  <pre><code>x = np.array((100, 100, 100, 3, 3))
  </code></pre>
  
  <p>However, this way I am not able to take advantage of the matrix object class and its functions.</p>
  
  <p>[EDIT]</p>
  
  <p>One thing I now realised is that I can cast an array to numpy matrix. So, using something like:</p>
  
  <pre><code>x = np.array((100, 100, 100, 3, 3))
  a = np.matrix(x[1, 1, 1])
  </code></pre>
  
  <p>However, I wonder if there is a more direct way.</p>
  
  <p>[MORE EDIT]</p>
  
  <p>After reading comments, it seems the numpy matrix class is not really that useful. I can do something like the following to compute the inverse, for example:</p>
  
  <pre><code>x = np.array((100, 100, 100, 3, 3))
  a = np.matrix(x[1, 1, 1])
  a_inv = np.linalg.inv(a)
  </code></pre>