问题描述
我不记得 np.zeros(x)
是否会自动将浮点 x
转换为 int,所以我在 IDLE 中尝试了它.我第一次得到的是一条警告消息,它指的是我之前在同一会话中运行的脚本,然后警告我使用非整数而不是整数将导致将来出现错误".
我又试了一次,警告没有重复,用dtype=float
按预期实例化了数组.
为什么警告说会有一个错误(而不是可能),它会是什么?为什么它指的是我今天早些时候运行的脚本中的第一个非空行被嵌入到警告中?
这可能是了解 IDLE 工作方式的一个窗口 - 所以我希望能从中学到一些东西.我已经在这里阅读我可以取消警告,但我想先了解它的行为.
>>>>>>赤道 = np.zeros(3.14)警告(来自警告模块):文件/Users/xxxxxx/Documents/xxxxxx/CYGNSS/CYGNSS TLE interpolator v00.py",第2行CYGNSS_BLOB = """1 41884U 16078A 16350.61686218 -.00000033 00000-0 00000+0 0 9996VisibleDeprecationWarning:使用非整数而不是整数会导致将来出错>>>>>>赤道 = np.zeros(3.14)>>>赤道数组([ 0., 0., 0.])>>>在未来"的意思是在 NumPy 的未来版本中".到目前为止,您收到的是警告,而不是错误.分配已完成(您不需要第二次运行该命令,eqator
已经根据您的需要分配了)并且执行正常进行.
但是某些未来版本的 NumPy 会抛出错误,停止执行.
警告不会在同一个会话中再次重复;有一些逻辑旨在避免过多地唠叨用户.
我无法解释行参考;对我来说,它指的是 __main__:1:
.
I couldn't remember if np.zeros(x)
will automatically covert a float x
to int or not, so I tried it in IDLE. What I got the first time was a Warning message that refers to the script I had run earlier in the same session, and then warns me "using a non-integer number instead of an integer will result in an error in the future".
I tried it again, and the warning did not repeat, and the array was instantiated as expected with dtype=float
.
Why does the warning say there will be an error (as opposed to could be), and what will it be? And why did it refer to the first non-blank line in the script I'd run much earlier today get embedded into the warning?
This may be a window into how IDLE is working - so I'm hoping to learn something from this. I've read here that I can suppress the warning, but I would like to understand it's behavior first.
>>>
>>> equator = np.zeros(3.14)
Warning (from warnings module):
File "/Users/xxxxxx/Documents/xxxxxx/CYGNSS/CYGNSS TLE interpolator v00.py", line 2
CYGNSS_BLOB = """1 41884U 16078A 16350.61686218 -.00000033 00000-0 00000+0 0 9996
VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future
>>>
>>> equator = np.zeros(3.14)
>>> equator
array([ 0., 0., 0.])
>>>
"In the future" means "in a future version of NumPy". So far you get a warning, not an error. The assignment was made (you didn't need to run the command the second time, equator
was already assigned as you wanted) and execution proceeded normally.
But some future version of NumPy will throw an error, halting the execution.
The warning is not repeated again within the same session; there's some logic there intended to avoid nagging the user too much.
I can't explain the line reference; for me it refers to __main__:1:
.
这篇关于为什么 Python 给了我这个奇怪的 Visible Deprecation Warning?有什么可以在这里学习的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!