title: Is there a way in numpy to test whether a matrix is Unitary
body: <p>I was wondering if there is any function in numpy to determine whether a matrix is Unitary?</p>
  
  <p>This is the function I wrote but it is not working. I would be thankful if you guys can find an error in my function and/or tell me another way to find out if a given matrix is unitary.</p>
  
  <pre><code>def is_unitary(matrix: np.ndarray) -&gt; bool:
  
      unitary = True
      n = matrix.size
      error = np.linalg.norm(np.eye(n) - matrix.dot( matrix.transpose().conjugate()))
  
      if not(error &lt; np.finfo(matrix.dtype).eps * 10.0 *n):
          unitary = False
  
      return unitary
  </code></pre>