Python | Numpy np.can_cast() method

With the help of np.can_cast() method, we can get the perfect idea that one data type can be able to cast into another data type or not by using np.can_cast() method.

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 :
In this example we can see that by using np.can_cast() method, we are able to get the boolean value as true when casting can be performed else false by using this method.

filter_none

edit
close

play_arrow

link
brightness_4
code

# import numpy
import numpy as np
  
# using np.can_cast() method
gfg = np.can_cast(np.int32, np.int64)
  
print(gfg)

chevron_right


Output :

True



Example #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# import numpy
import numpy as np
  
# using np.can_cast() method
gfg = np.can_cast(5.5e10, np.int32)
  
print(gfg)

chevron_right


Output :

False

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.