0

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])
  • `a[locs]` should be enough. You are just selecting blocks 2 and 5 on the first dimension. Or `a[[2,5], :, :]` (the trailing ':' are automatic). – hpaulj Sep 01 '20 at 03:27
  • 1
    `a` is a (6,3,4) shaped array. You don't need all those `np.asarray`; just one will do. – hpaulj Sep 01 '20 at 03:28
  • What was the purpose for using `[locs]` in the first place? Or is this old code from someone else? – hpaulj Sep 01 '20 at 06:27

1 Answers1

1

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.

Anurag Reddy
  • 1,159
  • 11
  • 19