What does python slicing syntax mean [o:,:]

Just a small and probably very simple question. Someone gave me the following line of code:

im = axs[0,i].pcolormesh(imgX[o:,:], imgY[o:,:], img.mean(-1)[o:,:], cmap='Greys')

I know ":" means everything in this column or row (or the depth of the array, depending on how you look at it). But what does "o:" mean?

+4
source share
2 answers

The following does not apply to use, but shows how the operation is “parsed”.


class X:
   def __getitem__(self, index):
       return index

X()[:,:]
>> (slice(None,None,None), slice(None,None,None))

And with different meanings for clarity:

X()[0, 1:, 3:4, 5:6:7]
>> (0, slice(1,None,None), slice(3,4,None), slice(5,6,7))

So, bearing in mind img[o:,:]how img[o:, :], how

img.__getitem__( (slice(o,None,None), slice(None,None,None)) )
+3
source

o - this is a variable, like any other (but with a very bad name, since it can be confused with zero).

[o:, :] " , o, . o .

, , , .

+2

Source: https://habr.com/ru/post/1529779/


All Articles