integer Indexing of a 3D numpy array gave me 5D array as output

Viewed 16

I have an array:

generator = np.random.default_rng(2357) ur_colle_data = np.round(generator.normal(loc=100,scale=5,size=(5,2,4))) where ur_colle_data:

array([[[106., 103., 92., 100.], [ 94., 102., 94., 100.]],

   [[104.,  96., 109.,  96.],
    [101., 104., 102.,  92.]],

   [[102., 102., 108., 101.],
    [ 91., 101., 106.,  99.]],

   [[101.,  98.,  95., 102.],
    [100., 101.,  99.,  93.]],

   [[107., 101., 104., 105.],
    [102.,  97., 101., 102.]]])

And I have a coordinates:

coord = array([[[0, 2], [1, 3]],

   [[1, 2],
    [0, 0]],

   [[0, 0],
    [1, 2]],

   [[1, 1],
    [0, 1]],

   [[0, 1],
    [1, 0]]])

When I do ur_colle_data[coord], I get a 5,2,2,2,4 shaped array instead.

the output: array([[[[[106., 103., 92., 100.], [ 94., 102., 94., 100.]],

     [[102., 102., 108., 101.],
      [ 91., 101., 106.,  99.]]],


    [[[104.,  96., 109.,  96.],
      [101., 104., 102.,  92.]],

     [[101.,  98.,  95., 102.],
      [100., 101.,  99.,  93.]]]],



   [[[[104.,  96., 109.,  96.],
      [101., 104., 102.,  92.]],

     [[102., 102., 108., 101.],
      [ 91., 101., 106.,  99.]]],


    [[[106., 103.,  92., 100.],
      [ 94., 102.,  94., 100.]],

     [[106., 103.,  92., 100.],
      [ 94., 102.,  94., 100.]]]],



   [[[[106., 103.,  92., 100.],
      [ 94., 102.,  94., 100.]],

     [[106., 103.,  92., 100.],
      [ 94., 102.,  94., 100.]]],


    [[[104.,  96., 109.,  96.],
      [101., 104., 102.,  92.]],

     [[102., 102., 108., 101.],
      [ 91., 101., 106.,  99.]]]],



   [[[[104.,  96., 109.,  96.],
      [101., 104., 102.,  92.]],

     [[104.,  96., 109.,  96.],
      [101., 104., 102.,  92.]]],


    [[[106., 103.,  92., 100.],
      [ 94., 102.,  94., 100.]],

     [[104.,  96., 109.,  96.],
      [101., 104., 102.,  92.]]]],



   [[[[106., 103.,  92., 100.],
      [ 94., 102.,  94., 100.]],

     [[104.,  96., 109.,  96.],
      [101., 104., 102.,  92.]]],


    [[[104.,  96., 109.,  96.],
      [101., 104., 102.,  92.]],

     [[106., 103.,  92., 100.],
      [ 94., 102.,  94., 100.]]]]])

May I know if anyone is familiar with how numpy in python does its indexing and why do i get such a weird output.

I was expecting a shape of output (2,2) instead.

0 Answers
Related