(e)
return e
Flatten a 1x1 matrix to a scalar, return larger matrices unchanged.
Flatten a 1x1 matrix to a scalar, return larger matrices unchanged.
Flatten a 1x1 matrix to a scalar return larger matrices unchanged .
def flatten_scalar(e):
    """Flatten a 1x1 matrix to a scalar, return larger matrices unchanged."""
    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