O'Reilly logo

Learning pandas by Michael Heydt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Selecting array elements

NumPy arrays can have their elements accessed via the [] operator. There are many variants of this operator that we will see throughout this book, but the basic access to array elements is by passing the zero-based offset of the desired element:

In [24]:
   # select 0-based elements 0 and 2
   a1[0], a1[2]

Out[24]:
   (0, 2)

Elements in a two-dimensional array can be used by making use of two values separated by a comma, with the row first and column second:

In [25]:
   # select an element in 2d array at row 1 column 2
   m[1, 2]

Out[25]:
   6

It is possible to retrieve an entire row of a two-dimensional array using just a single value representing the row and omitting the column component:

In [26]:
# all items in row 1
m[1,]

Out[26]: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required