问题
I'm getting this warning in jupyter notebook.
/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:10: DeprecationWarning: object of type <class 'float'> cannot be safely interpreted as an integer.
# Remove the CWD from sys.path while we load stuff.
/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:11: DeprecationWarning: object of type <class 'float'> cannot be safely interpreted as an integer.
# This is added back by InteractiveShellApp.init_path()
It's annoying because it shows up in every run I do:
How do I fix or disable it?
回答1:
If you are sure your code is correct and simple want to get rid of this warning and all other warnings in the notebook do the following:
import warnings
warnings.filterwarnings('ignore')
回答2:
Try this:
import warnings
warnings.filterwarnings('ignore')
warnings.simplefilter('ignore')
回答3:
You will get this warning if you pass an argument as float, that should be an integer.
E.g., in the following example, num should be an integer, but is passed as float:
import numpy as np
np.linspace(0, 10, num=3.0)
This prints the warning you got:
ipykernel_launcher.py:2: DeprecationWarning: object of type <class 'float'> cannot be safely interpreted as an integer.
Since parts of your code are missing, I cannot figure out, which parameter should be passed as integer, but the following example shows how to fix this:
import numpy as np
np.linspace(0, 10, num=int(3.0))
来源:https://stackoverflow.com/questions/48828824/disable-warnings-in-jupyter-notebook