DEV Community

TechPlygrnd
TechPlygrnd

Posted on

NumPy Tutorial #3: Array Indexing

In the previous blog, I have showed you how to create a NumPy array. In this blog, I will show you how to access data inside the array using index.

First of all, you can create a NumPy array for the example

import numpy as np

list_of_number = [1, 2, 3, 4, 5]

arr = np.array(list_of_number)
Enter fullscreen mode Exit fullscreen mode

To get the data inside the array, you can use index to indicate the position of the data. For example, if you run this code

print(arr[2])
Enter fullscreen mode Exit fullscreen mode

it will output

3
Enter fullscreen mode Exit fullscreen mode

And if you run

print(arr[4])
Enter fullscreen mode Exit fullscreen mode

you will get

5
Enter fullscreen mode Exit fullscreen mode

Congratulations! you now know how to access data inside NumPy array using indexing. Thank you for reading this blog, see you next time!

Top comments (0)