The function np.mean requires parentheses around the argument, like np.mean(arr).
Step 2: Identify the error in the code
The code uses np.mean arr without parentheses, causing a syntax error.
Final Answer:
Missing parentheses after np.mean -> Option D
Quick Check:
Functions need parentheses: np.mean(arr) [OK]
Hint: Always use parentheses when calling functions [OK]
Common Mistakes:
Forgetting parentheses on function calls
Thinking np.mean can't handle arrays
Misreading print syntax as error
5. You have an array of temperatures in Celsius: temps = np.array([0, 20, 37, 100]). You want to convert them to Fahrenheit using the formula F = C * 9/5 + 32. Which NumPy code correctly applies this math function to all elements?
hard
A. fahrenheit = temps * 9 / (5 + 32)
B. fahrenheit = np.add(temps, 32) * 9 / 5
C. fahrenheit = np.multiply(temps, 9/5) + 32
D. fahrenheit = temps + 32 * 9 / 5
Solution
Step 1: Understand the formula and vectorized operations
The formula is F = C * 9/5 + 32. NumPy allows element-wise multiplication and addition.
Step 2: Check each option for correct order and operations