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
  • 138,671
  • 33
  • 247
  • 280
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 - stand with Ukraine
  • 205,989
  • 36
  • 386
  • 419
0

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

Błotosmętek
  • 12,717
  • 19
  • 29