def ensure_dtype_float ( x , default = np . float64 ) : if isinstance ( x , np . ndarray ) : if x . dtype . kind == 'f' : return x elif x . dtype . kind == 'i' : return x . astype ( default ) else : raise TypeError ( 'x is of type ' + str ( x . dtype ) + ' that cannot be converted to float' ) else : raise TypeError ( 'x is not an array' )
force an array to be float in python
r Makes sure that x is type of float
def ensure_dtype_float(x, default=np.float64):
    r"""Makes sure that x is type of float

    """
    if isinstance(x, np.ndarray):
        if x.dtype.kind == 'f':
            return x
        elif x.dtype.kind == 'i':
            return x.astype(default)
        else:
            raise TypeError('x is of type '+str(x.dtype)+' that cannot be converted to float')
    else:
        raise TypeError('x is not an array')