def flatten_scalar(e):
 if isinstance(e, Matrix):
  if (e.shape == (1, 1)):
   e = e[0]
 if isinstance(e, (numpy_ndarray, scipy_sparse_matrix)):
  if (e.shape == (1, 1)):
   e = complex(e[(0, 0)])
 return e

def flatten_scalar ( e ) : if isinstance ( e , Matrix ) : if ( e . shape == ( 1 , 1 ) ) : e = e [ 0 ] if isinstance ( e , ( numpy_ndarray , scipy_sparse_matrix ) ) : if ( e . shape == ( 1 , 1 ) ) : e = complex ( e [ ( 0 , 0 ) ] ) return e
flatten a 1x1 matrix to a scalar .