0

The following:

arr2d = np.array([[5,10,15],[15,20,25],[30,35,40]])

arr2d[:2,1:]

Produces:

array([[10, 15],
       [20, 25]])

I would like to know how the result is calculated.

Jon Clements
  • 132,101
  • 31
  • 237
  • 267
Morris
  • 3
  • 2

2 Answers2

0

I think you want to read about Numpy indexing

In [54]: arr2d[:2,1:]
Out[54]:
array([[10, 15],
       [20, 25]])

means - give me first two rows and all columns starting from the second one (1)

In [56]: arr2d[:2,:]
Out[56]:
array([[ 5, 10, 15],
       [15, 20, 25]])

In [57]: arr2d[:2,1:]
Out[57]:
array([[10, 15],
       [20, 25]])
MaxU - stop genocide of UA
  • 191,778
  • 30
  • 340
  • 375
0

arr2d[:2,1:] means "rows up to (but not including!) 2, columns 1 to last".

Błotosmętek
  • 12,365
  • 18
  • 29