Skip to main contentSkip to solution

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

✅ Correct Option: 1

(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.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question