Member-only story

NumPy Tutorial: Accessing Array Items

Jesse L
2 min readOct 4, 2021

--

Hi everyone, welcome back. NumPy is a library for the Python programming language. NumPy is short for “Numerical Python” and is a popular library that is used in data science. NumPy is used specifically to work with arrays as it provides various functions and support. We will go over how to access Array items in NumPy.

Accessing Array Items

Indexes can be used to access an item within an array. Arrays in NumPy have indexes starting with 0. The first item in an array would have an index of 0 and the second item in an array would have an index of 1 and so on.

Let’s see what it looks like when we retrieve our first item at index 0:

import numpy as np

myArray = np.array([1, 2, 3])
print(myArray[0])
Output:
1

We have successfully retrieved our first item at index 0 which is “1” and printed it in our output.

Let’s now retrieve our item at index 1:

import numpy as np

myArray = np.array([1, 2, 3])
print(myArray[1])
Output:
2

Our item at index 1 is “2” and we have successfully retrieved that value as well.

So how do you access an item in a 2D array or higher dimensions arrays? That is done by providing the index of each…

--

--

Jesse L
Jesse L

Written by Jesse L

Hi, I'm a passionate technology enthusiast and lifelong learner. Beyond my technical pursuits, I'm also passionate about sharing my enthusiasm with others.

No responses yet