Published on January 26, 2024By DeveloperBreeze
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)
Comments
Please log in to leave a comment.