pythonarraysnumpyindexingfuture-warning

How to properly adjust code due to this futurewarning? (multidimensional indexing numpy)


How to adjust the indexing in this code, so that it will work properly due to this FutureWarning?

D:/Arc/Arc_Project\Architecture\_Z07_Adjust_X_Y\backward_sequentialize.py:165: 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.
a = np.asarray([
           np.asarray([
              np.asarray([1,1,1,1]),
              np.asarray([1,1,0,1]),
              np.asarray([1,1,1,1])
                                  ]),
          np.asarray([
              np.asarray([1,1,1,1]),
              np.asarray([1,1,1,1]),
              np.asarray([1,1,1,1])
                                  ]),
         np.asarray([
              np.asarray([1,1,1,1]),
              np.asarray([1,1,2,1]),
              np.asarray([1,1,1,1])
                                  ])
         np.asarray([
              np.asarray([1,1,1,1]),
              np.asarray([1,1,3,1]),
              np.asarray([1,1,1,1])
                                  ])
         np.asarray([
              np.asarray([1,1,1,1]),
              np.asarray([1,1,4,1]),
              np.asarray([1,1,1,1])
                                  ])
         np.asarray([
              np.asarray([1,1,1,1]),
              np.asarray([1,1,5,1]),
              np.asarray([1,1,1,1])
                                  ]) ])
locs = [2,5]
print(a[[locs]])
         [ [1,1,1,1]
           [1,1,2,1]
           [1,1,1,1] ]
         [ [1,1,1,1]
           [1,1,5,1]
           [1,1,1,1] ]

am i getting it right that locs = tuple([2,5]) will do it?

EDIT: i dont just want the warning to disappear, because as it says it will probably not work properly in the future.

EDIT: I am also doing this: (how to adjust that too?)

    a = np.array([x[-(SEQ_LEN):] for x in a])

Solution

  • For accessing the given elements just send the array of the required indices followed by the , to represent the other axes and return the required ones in the given axis.

    array[([2,5],)], that should take care of it.