DeveloperBreeze

Filtering and Selecting Elements in NumPy Array

import numpy as np

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

# Use boolean indexing to filter elements greater than 30
filtered_arr = arr[arr > 30]
print("Filtered Array (elements > 30):", filtered_arr)

# Use integer indexing to select elements at specific indices
selected_indices = [0, 2, 4]
selected_elements = arr[selected_indices]
print("Selected Elements (by index):", selected_elements)

Continue Reading

Handpicked posts just for you — based on your current read.

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!