当前位置: 首页 > 面试题库 >

FutureWarning:不推荐将非元组序列用于多维索引,请使用`arr [tuple(seq)]`

金珂
2023-03-14
问题内容

我已经搜索过S / O,但是找不到答案。

当我尝试使用seaborn绘制分布图时,我会得到未来的警告。我想知道这里可能是什么问题。

import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
% matplotlib inline
from sklearn import datasets

iris = datasets.load_iris()
df = pd.DataFrame(iris.data, columns=iris.feature_names)
df['class'] = iris.target
df['species'] = df['class'].map({idx:s for idx, s in enumerate(iris.target_names)})


fig, ((ax1,ax2),(ax3,ax4))= plt.subplots(2,2, figsize =(13,9))
sns.distplot(a = df.iloc[:,0], ax=ax1)
sns.distplot(a = df.iloc[:,1], ax=ax2)
sns.distplot(a = df.iloc[:,2], ax=ax3)
sns.distplot(a = df.iloc[:,3], ax=ax4)
plt.show()

这是警告:

C:\ProgramData\Anaconda3\lib\site-packages\scipy\stats\stats.py:1713:
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.
return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval

有什么帮助吗?您可以运行上面的代码。您会收到警告。

熊猫:0.23.4,seaborn:0.9.0,matplotlib:2.2.3,scipy:1.1.0,numpy:1.15.0'


问题答案:

更全面的追溯将是很好的。我的猜测是,seaborn.distplot使用scipy.stats计算的东西。错误发生在

def _compute_qth_percentile(sorted, per, interpolation_method, axis):
    ....
    indexer = [slice(None)] * sorted.ndim
    ...
    indexer[axis] = slice(i, i + 2)
    ...
    return np.add.reduce(sorted[indexer] * weights, axis=axis) / sumval

因此,在最后一行中,该列表indexer用于slice sorted

In [81]: x = np.arange(12).reshape(3,4)
In [83]: indexer = [slice(None), slice(None,2)]
In [84]: x[indexer]
/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[84]: 
array([[0, 1],
       [4, 5],
       [8, 9]])
In [85]: x[tuple(indexer)]
Out[85]: 
array([[0, 1],
       [4, 5],
       [8, 9]])

使用切片列表是可行的,但是计划将来会贬值。涉及多个维度的索引应该是元组。在上下文中使用列表是一种较旧的样式,正在逐步淘汰。

因此,scipy开发人员需要解决此问题。这不是最终用户应该处理的事情。但是目前,不用担心futurewarning。它不影响计算或绘图。有一种方法可以抑制将来的警告,但是我不知道这是不是可以立即使用的。

FutureWarning:不建议使用非元组序列进行多维索引编制,而应使用arr [tuple(seq)]而非arr [seq]



 类似资料:
  • 问题内容: 我有一个问题: 当应用程序启动时,它显示警告: WARN 7388 — [main] org.hibernate.orm.deprecation:HHH90000014:发现使用不推荐使用的[org.hibernate.id.SequenceHiLoGenerator]基于序列的id生成器;请改用org.hibernate.id.enhanced.SequenceStyleGenera

  • 我使用的是PostgreSQL v9。6.6. 我正在运行以下SQL: 这将导致以下错误,因为列的索引不是唯一的。我不能添加索引,因为有一些存量数据不是唯一的。 错误:不存在与冲突规范匹配的唯一或排除约束 问:有没有办法在没有索引的情况下执行upsert语句? 谢谢

  • 问题内容: 我一直在关注有关如何将数据从android应用程序插入数据库的在线教程,并使这一切工作正常,除了这一小部分 不推荐使用NameValuePair和BasicNameValuePair,而推荐使用。我该如何创建一个新值关联?http://developer.android.com/reference/java/net/URL.html#openConnection() 有谁知道我如何使用

  • 问题内容: 我收到此警告,但是该程序仍然可以正常运行。 MySQL代码向我显示了一条PHP消息: 不推荐使用:mysql_connect():不推荐使用mysql扩展,以后将被删除:在第2行的C:\ xampp \ htdocs \ task \ media \ new \ connect.inc.php中使用mysqli或PDO代替 我的页面是 这是什么意思,我该如何消除该消息? 问题答案: 有

  • 问题内容: 我正在尝试使用和进行单元测试。 当我不包含注释时,测试将失败。但 不推荐使用MockitoJUnitRunner类型 我正在使用Mockito 2.6.9。我应该怎么做? 问题答案: 现在确实已弃用,应该改为使用。如您所见,仅软件包名称已更改,该类的简单名称仍为 。 摘录自javadoc : 移至,该课程将在Mockito 3中删除

  • 新的侦听器(又名OnCameraMoveListener())方法onCameraMove()没有CameraPosition CameraPosition输入变量,所以我很迷惑:有没有方法回收我的旧代码? 这里有一些参考资料。