import numpy as np

class QuantumGate:
    def __init__(self, matrix):
        self.matrix = matrix
        if(not self.__is_unitary()):
            raise Exception("Supplied matrix is not unitary")

    def __is_unitary(self):
        shape = np.shape(self.matrix)
        # unitary matrices will always have dimension n*n
        x = shape[0]
        y = shape[1]
        if(x != y):
            return False
        # unitary matrices must satisfy U*U = UU* = I
        identity = self.matrix.getI()
        conjugate_transpose = self.matrix.getH()
		# TODO needs studying - this only checks the UU* = I part of equation
        return (self.matrix * conjugate_transpose).all() == identity.all()

if __name__ == '__main__':
    qg = QuantumGate(np.matrix('0 1; 1 0', np.complex_))
@@ -326,16 +326,19 @@
        x
+, y
  = shape
@@ -344,20 +344,9 @@
 e%5B0%5D
-%0A        y =
+,
  sha
@@ -768,8 +768,9 @@
 mplex_))
+%0A

make matrix shape check shorter