0

For an numpy A, what does A[::-1] do?

A[::-1]

'-1' means any dimension of column?

What about 2 dots? For example, the new array doesn't change:

In [11]: x = np.indices((3,3))                                                                                                                                                        

In [12]: x                                                                                                                                                                            
Out[12]: 
array([[[0, 0, 0],
        [1, 1, 1],
        [2, 2, 2]],

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

In [13]: type(x)                                                                                                                                                                      
Out[13]: numpy.ndarray

In [14]: x[::-1]                                                                                                                                                                      
Out[14]: 
array([[[0, 1, 2],
        [0, 1, 2],
        [0, 1, 2]],

       [[0, 0, 0],
        [1, 1, 1],
        [2, 2, 2]]])
walnut
  • 21,629
  • 4
  • 23
  • 59
ling
  • 1,555
  • 3
  • 18
  • 24
  • 1
    From duplicate's top answer: `a[::-1] # all items in the array, reversed` – walnut Oct 18 '19 at 23:02
  • That `x` is a (2,3,3) shape (`x.shape`). `x[::-1]` slices the first dimension, the size 2 one. Slice notation is `start:stop:step`, here it means reverse. The two blocks are switched in `Out[14]`. – hpaulj Oct 19 '19 at 00:04
  • You might want to start by experimenting with python lists. `x = [1,2,3,4,5,6]` and `x[2:]` and `x[::2]` and `x[::-1]`. The array indexing builds on the patterns established for lists. – hpaulj Oct 19 '19 at 00:53

0 Answers0