Returns True if cast between data types can occur without losing precision.
Parameters: | fromtype : dtype or dtype specifier
totype : dtype or dtype specifier
|
---|---|
Returns: | out : bool
|
Examples
>>> np.can_cast(np.int32, np.int64)
True
>>> np.can_cast(np.float64, np.complex)
True
>>> np.can_cast(np.complex, np.float)
False
>>> np.can_cast('i8', 'f8')
True
>>> np.can_cast('i8', 'f4')
False
>>> np.can_cast('i4', 'S4')
True