How do I index lists in Python using NumPy?

In Python, you can use NumPy to index lists (or more accurately, NumPy arrays) efficiently. NumPy provides powerful indexing capabilities that allow you to select elements from arrays in a variety of ways, such as using integers, slices, boolean arrays, or even advanced indexing.

Keywords: NumPy, Indexing, Python Lists, Arrays, Data Manipulation, Data Analysis
Description: Learn how to index lists in Python using NumPy to enhance your data manipulation capabilities. Discover various indexing techniques that can simplify your array manipulation tasks.

import numpy as np

# Create a NumPy array
arr = np.array([10, 20, 30, 40, 50])

# Simple index
print(arr[2])  # Output: 30

# Slicing
print(arr[1:4])  # Output: [20 30 40]

# Boolean indexing
print(arr[arr > 30])  # Output: [40 50]

# Advanced indexing
indices = [0, 2, 3]
print(arr[indices])  # Output: [10 30 40]
    

Keywords: NumPy Indexing Python Lists Arrays Data Manipulation Data Analysis