NumPy is a popular Python library. What is its main use?
Think about what kind of data structure NumPy mainly works with.
NumPy provides efficient tools to work with arrays and matrices, enabling fast numerical calculations.
Look at the code below. What will it print?
import numpy as np arr = np.array([1, 2, 3]) print(arr * 2)
Multiplying a NumPy array by a number multiplies each element.
NumPy arrays support element-wise operations. Multiplying by 2 doubles each element.
Consider this code creating a 2D array. What is the shape of arr?
import numpy as np arr = np.array([[1, 2, 3], [4, 5, 6]]) print(arr.shape)
Count rows and columns in the nested list.
The array has 2 rows and 3 columns, so its shape is (2, 3).
What error will this code produce?
import numpy as np arr = np.array([1, 2, 3]) print(arr[3])
Remember Python indexing starts at 0 and the last index is length-1.
Index 3 is out of range for an array of size 3 (indices 0,1,2).
Given arr = np.array([1, 2, 3, 4, 5]), which code correctly calculates the mean?
import numpy as np arr = np.array([1, 2, 3, 4, 5])
Think about different ways to calculate average in NumPy.
All options A, B, and D correctly compute the mean of the array.