FutureWarning:不推荐使用非元组序列进行多维索引,使用 `arr[tuple(seq)]` [英] FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated use `arr[tuple(seq)]`

查看:29
本文介绍了FutureWarning:不推荐使用非元组序列进行多维索引,使用 `arr[tuple(seq)]`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have searched S/O but I couldn't find a answer for this.

当我尝试使用 seaborn 绘制分布图时,我收到了未来警告.我想知道这里可能有什么问题.

When I try to plot a distribution plot using seaborn I am getting a futurewarning. I was wondering what could be the issue here.

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:ProgramDataAnaconda3libsite-packagesscipystatsstats.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

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

Any help? You can run the above code. You'll get the warning.

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

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

推荐答案

更完整的追溯会更好.我的猜测是 seaborn.distplot 正在使用 scipy.stats 来计算一些东西.错误发生在

A fuller traceback would be nice. My guess is that seaborn.distplot is using scipy.stats to calculate something. The error occurs in

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 用于对 sorted 进行切片.

So in this last line, the list indexer is used to 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]])

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

Using a list of slices works, but the plan is to depreciate in the future. Indexes that involve several dimensions are supposed to be tuples. The use of lists in the context is an older style that is being phased out.

所以 scipy 开发人员需要解决这个问题.这不是最终用户应该处理的事情.但是现在,不要担心 futurewarning.它不影响计算或绘图.有一种方法可以抑制未来的警告,但我不知道.

So the scipy developers need to fix this. This isn't something end users should have to deal with. But for now, don't worry about the futurewarning. It doesn't affect the calculations or plotting. There is a way of suppressing future warnings, but I don't know it off hand.

FutureWarning:使用非元组多维索引的序列已被弃用,使用 `arr[tuple(seq)]` 而不是 `arr[seq]`

这篇关于FutureWarning:不推荐使用非元组序列进行多维索引,使用 `arr[tuple(seq)]`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆