Python | Numpy np.can_cast () method

NumPy | Python Methods and Functions

With the np.can_cast() method we can get a perfect idea that one data type can be converted to another data type or not using np.can_cast () .

Syntax: np.can_cast (source data_type, target data_type)
Return: Return the boolean value as true when casting can be done else false.

Example # 1:
B In this example, we can see that using np.can_cast () , we can get a boolean value as true when the cast can be performed, otherwise false using this method.

# NumPy import

import numpy as np

 
 # using the np.can_cast () method

gfg = np.can_cast (np.int32, np.int64)

  

print (gfg)

Output:

True

Example # 2:

# NumPy import

import numpy as np

  
# using the np.can_cast () method

gfg = np.can_cast ( 5.5e10 , np.int32)

  

print (gfg)

Output:

False





Get Solution for free from DataCamp guru