Bird
0
0

What is the output of the following code?

medium📝 Predict Output Q4 of 15
NumPy - Creating Arrays
What is the output of the following code?
import numpy as np
arr = np.linspace(0, 1, 5)
print(arr)
A[0. 0.5 1. 1.5 2. ]
B[0. 0.2 0.4 0.6 0.8]
C[0. 0.25 0.5 0.75 1. ]
D[0. 0.1 0.2 0.3 0.4]
Step-by-Step Solution
Solution:
  1. Step 1: Understand np.linspace(0, 1, 5)

    It creates 5 numbers evenly spaced from 0 to 1.
  2. Step 2: Calculate spacing

    Spacing = (1 - 0) / (5 - 1) = 0.25, so numbers are 0, 0.25, 0.5, 0.75, 1.
  3. Final Answer:

    [0. 0.25 0.5 0.75 1. ] -> Option C
  4. Quick Check:

    Even spacing with 5 points = [0,0.25,0.5,0.75,1] [OK]
Quick Trick: Spacing = (stop - start) / (num - 1) [OK]
Common Mistakes:
  • Confusing number of points with step size
  • Off-by-one errors in spacing calculation
  • Assuming default step size instead of num points

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes