发布于2019-09-01 20:07 阅读(878) 评论(0) 点赞(13) 收藏(4)
我不想将非元组序列用于多维索引,以便脚本在此更改时支持Python的未来版本。
下面是我用于绘制图形的代码:
data = np.genfromtxt(Example.csv,delimiter=',', dtype=None, names=True,
converters={0: str2date})
p1, = host.plot(data["column_1"], data["column_2"], "b-", label="column_2")
p2, = par1.plot(data["column_1"], data['column_3'], "r-", label="column_3")
p3, = par2.plot(data["column_1"], data["column_4"], "g-", label="column_4")
host.set_xlim([data["column_1"][0], data["column_1"][-1]])
host.set_ylim(data["column_2"].min(), data["column_2"].max())
par1.set_ylim(data["column_3"].min(), data["column_3"].max())
par2.set_ylim(data["column_4"].min(), data["column_4"].max())
我可以通过以下方式重现警告:
In [313]: x = np.zeros((4,2))
In [315]: x[:,1]
Out[315]: array([0., 0., 0., 0.])
通过替换:
a,slice(None)
我们可以将此索引编写为:
In [316]: x[[slice(None),1]]
/usr/local/bin/ipython3:1: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
#!/usr/bin/python3
Out[316]: array([0., 0., 0., 0.])
它应该是一个元组,而不是一个列表:
In [317]: x[(slice(None),1)]
Out[317]: array([0., 0., 0., 0.])
In [318]: x[tuple([slice(None),1])]
Out[318]: array([0., 0., 0., 0.])
警告告诉我们列表格式过去没问题,但将来会产生错误。
我没有看到任何代码在列表索引中执行此类切片。
data
from genfromtxt
是一个结构化数组,因此按字段名称索引是正常的:data["column_1"]
。所以警告很可能是在plot
代码中生成的。但我们对于哪里没有任何线索。警告不会给出任何类型的错误堆栈跟踪,这样做吗?
因此,如果没有类似的示例数组data
或csv文件Example.csv
,我们无法重现警告,并进一步挖掘。
首先,我会print
在每个代码行之间添加一些内容。目标是确定哪个matplotlib
呼叫产生警告。
例如,如果它是生产的
host.set_xlim([data["column_1"][0], data["column_1"][-1]])
我可能会尝试将该调用更改为
host.set_xlim((data["column_1"][0], data["column_1"][-1]))
要么
host.set_xlim(data["column_1"][0], data["column_1"][-1])
这有点疯狂猜测......
FutureWarning:不推荐使用非元组序列进行多维索引使用`arr [tuple(seq)]`
这个最新的SO,帮助我们识别scipy.stats
包中的问题功能。它构造了一个切片列表,并使用它而无需进一步转换为元组。
作者:黑洞官方问答小能手
链接:https://www.pythonheidong.com/blog/article/76153/e72817cfefd7834f10ef/
来源:python黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 python黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-1
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!