I am using an ndarray to slice another ndarray.
Normally I use arr[ind_arr]
. numpy
seems to not like this and raises a FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated use arr[tuple(seq)] instead of arr[seq]
.
What's the difference between arr[tuple(seq)]
and arr[seq]
?
Other questions on StackOverflow seem to be running into this error in scipy
and pandas
and most people suggest the error to be in the particular version of these packages. I am running into the warning running purely in numpy
.
Example posts:
FutureWarning with distplot in seaborn
MWE reproducing warning:
import numpy as np
# generate a random 2d array
A = np.random.randint(20, size=(7,7))
print(A, '\n')
# define indices
ind_i = np.array([1, 2, 3]) # along i
ind_j = np.array([5, 6]) # along j
# generate index array using meshgrid
ind_ij = np.meshgrid(ind_i, ind_j, indexing='ij')
B = A[ind_ij]
print(B, '\n')
C = A[tuple(ind_ij)]
print(C, '\n')
# note: both produce the same result