Arrange the following steps in the correct sequence to create a NumPy array and perform an element-wise square operation .
(A) import NumPy as np
(B) arr = np.array([1,2,3,4,5])
(C) arr_square = np.power(arr, 2)
(D) print(arr_square)
Arrange the following steps in the correct sequence to create a NumPy array and perform an element-wise square operation .
(A) import NumPy as np
(B) arr = np.array([1,2,3,4,5])
(C) arr_square = np.power(arr, 2)
(D) print(arr_square)
Solution
(A) import NumPy as np: the library must be imported before np can be used.
(B) arr = np.array([1,2,3,4,5]): creates the array.
(C) arr_square = np.power(arr, 2): squares each element of arr, so arr must already exist.
(D) print(arr_square): displays the result, which must already be computed.
Options 2 and 4: (C) comes before (B), so arr is not defined when it is squared.
Option 3: (B) comes before (A), so np is used before it is imported.
Related questions:
2026: 18 May Shift 2
2026: 29 May Shift 1
2025: 15 May Shift 2
2026: 29 May Shift 2