numpy.can_cast

numpy.can_cast(fromtype, totype)

Returns True if cast between data types can occur without losing precision.

Parameters :

fromtype : dtype or dtype specifier

Data type to cast from.

totype : dtype or dtype specifier

Data type to cast to.

Returns :

out : bool

True if cast can occur without losing precision.

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

Previous topic

numpy.mintypecode

Next topic

numpy.common_type

This Page