Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q13 of 15
NumPy - Array Data Types
What will be the output of this code?
import numpy as np
arr = np.array([127, 128], dtype='int8')
print(arr)
A[127 128]
B[127 -128]
C[127 0]
DError: value out of range
Step-by-Step Solution
Solution:
  1. Step 1: Understand int8 range

    int8 can store values from -128 to 127. The value 128 is outside this range.
  2. Step 2: Observe overflow behavior

    When 128 is stored in int8, it wraps around to -128 due to overflow.
  3. Final Answer:

    [127 -128] -> Option B
  4. Quick Check:

    int8 overflow wraps 128 to -128 [OK]
Quick Trick: int8 max is 127; values above wrap to negative [OK]
Common Mistakes:
  • Expecting 128 to store correctly in int8
  • Assuming error raised on overflow
  • Thinking 128 becomes 0

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes