import numpy as np arr = np.array([10, 20, 30, 40, 50]) slice_view = arr[1:4] slice_view[0] = 99 print(arr) fancy_index = arr[[1, 2, 3]] fancy_index[0] = 77 print(arr)
Slicing in NumPy returns a view of the original array, so modifying the slice changes the original array. Fancy indexing returns a copy, so modifying it does not affect the original array.
import numpy as np arr = np.array([5, 10, 15, 20, 25, 30]) mask = arr > 15 selected = arr[mask] print(len(selected))
The values greater than 15 are 20, 25, and 30, so 3 elements are selected.
import numpy as np arr = np.array([[1, 2], [3, 4], [5, 6]]) print(arr[[0, 2], 1, 0])
The array is 2D, but three indices are used. This causes an IndexError for too many indices.
import numpy as np arr = np.array([[1, 4], [3, 2], [5, 6], [4, 3]])
Option C uses element-wise logical AND with & and parentheses, which is correct. Option C uses OR, which selects more rows. Option C uses Python 'and' which is invalid for arrays. Option C uses wrong indexing syntax.
Slices in NumPy return views, which means they share the same memory as the original array. Changes to the slice affect the original. Fancy indexing returns a new array copy, so changes do not affect the original.