title: Matrix Multiplication with Object Arrays in Python
body: <p>I am wondering how matrix multiplication can be supported in numpy with arrays of <code>dtype=object</code>. I have homomorphically encrypted numbers that are encapsulated in a class <code>Ciphertext</code> for which I have overriden the basic math operators like <code>__add__</code>, <code>__mul__</code> etc.</p>
  
  <p>I have created numpy array where each entry is an instance of my class <code>Ciphertext</code> and numpy understands how to broadcast addition and multiplication operations just fine. </p>
  
  <pre><code>    encryptedInput = builder.encrypt_as_array(np.array([6,7])) # type(encryptedInput) is &lt;class 'numpy.ndarray'&gt;
      encryptedOutput = encryptedInput + encryptedInput
      builder.decrypt(encryptedOutput)                           # Result: np.array([12,14])
  </code></pre>
  
  <p>However, numpy won't let me do matrix multiplications</p>
  
  <pre><code>out = encryptedInput @ encryptedInput # TypeError: Object arrays are not currently supported
  </code></pre>
  
  <p>I don't quite understand why this happens considering that addition and multiplication works. I guess it has something to do with numpy not being able to know the shape of the object, since it could be a list or something fance. </p>
  
  <p><strong>Naive Solution</strong>: I could write my own class that extends <code>ndarray</code> and overwrite the <code>__matmul__</code> operation, but I would probably lose out on performance and also this approach entails implementing broadcasting etc., so I would basically reinvent the wheel for something that should work as it is right now. </p>
  
  <p><strong>Question</strong>: How can I use the standard matrix multiplication provided by numpy on arrays with <code>dtype=objects</code> where the objects behave exactly like numbers?</p>
  
  <p>Thank you in advance!</p>