0

We are using numpy in Python as b = np.array([[1,2,3],[4,5,6],[7,8,9]]). Then we use the command print(b[1:,:1]), I'm just trying to understand what the b[1:,:1] is referencing in the array.

The output is:

 [[4]
  [7]]

and I'm just trying to understand how that output is coming out if that makes sense.

I've tried looking it up on google but I havent been able to find an answer that explains well enough what is happening and how the array is being accesed by the [1:,:1].

mozway
  • 194,879
  • 13
  • 39
  • 75
  • This slices all rows after the second and all columns up to the second (excluded). – mozway Aug 31 '23 at 02:33
  • I assume you know what `xxx[1:]` means in a string or list, and also what `xxx[:1]` means. This is just using both -- one in the 1st dimension, one in the 2nd dimension. This is a numpy thing; Python doesn't allow multi-dimensional access in lists. – Tim Roberts Aug 31 '23 at 03:21
  • Look it up in the official numpy documentation. For example, https://numpy.org/doc/stable/user/basics.indexing.html - the basics indexing section. Google searches have their uses, but they aren't a substitute for actually learning the language and/or package from the documentation (or a good comprehensive book). Also beware of tutorials - - – hpaulj Aug 31 '23 at 03:31

0 Answers0