FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated use `arr[tuple(seq)]`

前端 未结 4 1118
予麋鹿
予麋鹿 2020-12-03 13:37

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

When I try to plot a distribution plot using seaborn I am getting a futurewarning. I was wondering what

4条回答
  •  生来不讨喜
    2020-12-03 14:04

    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
    

    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.

    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: Using a non-tuple sequence for multidimensional indexing is deprecated use `arr[tuple(seq)]` instead of `arr[seq]`

提交回复
热议问题