Bird
0
0

What is the output of the following code?

medium📝 Predict Output Q4 of 15
NumPy - Array Operations
What is the output of the following code?
import numpy as np
arr = np.array([10, 20, 30])
result = arr / 10
print(result)
AError: unsupported operand type(s)
B[1 2 3]
C[10 20 30]
D[1. 2. 3.]
Step-by-Step Solution
Solution:
  1. Step 1: Understand division of array by scalar

    Dividing an integer array by a scalar converts elements to floats and divides each element.
  2. Step 2: Calculate each element divided by 10

    10/10=1.0, 20/10=2.0, 30/10=3.0, so result is [1.0, 2.0, 3.0].
  3. Final Answer:

    [1. 2. 3.] -> Option D
  4. Quick Check:

    Scalar division = element-wise float division [OK]
Quick Trick: Division by scalar converts array elements to float [OK]
Common Mistakes:
  • Expecting integer division result
  • Confusing output format with list
  • Expecting error on scalar division

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes