Bird
0
0

Find the mistake in this code snippet:

medium📝 Debug Q7 of 15
NumPy - Creating Arrays
Find the mistake in this code snippet:
import numpy as np
arr = np.full((2, 2), '5')
print(arr + 1)
ACannot add integer to string array
BShape tuple is incorrect
Cnp.full() does not accept strings
DNo mistake, code runs fine
Step-by-Step Solution
Solution:
  1. Step 1: Analyze array data type

    The array is filled with string '5', so its dtype is string.
  2. Step 2: Check the operation

    Adding integer 1 to a string array causes a type error in NumPy.
  3. Final Answer:

    Cannot add integer to string array -> Option A
  4. Quick Check:

    Adding int to string array causes error [OK]
Quick Trick: Numeric operations need numeric array types [OK]
Common Mistakes:
  • Adding int to string arrays
  • Wrong shape tuple
  • Assuming np.full() rejects strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes