Bird
0
0

Find the mistake in this code:

medium📝 Debug Q7 of 15
NumPy - Array Data Types
Find the mistake in this code:
import numpy as np
z = np.array([1+2j, 3+4j], dtype=np.complex64)
print(z.imag())
AMissing import of complex module
Bdtype complex64 is invalid
Cimag is an attribute, not a method; parentheses cause error
DArray elements must be real numbers
Step-by-Step Solution
Solution:
  1. Step 1: Check usage of imag

    imag is an attribute, not a function, so it should be accessed without parentheses.
  2. Step 2: Identify error cause

    Calling z.imag() causes a TypeError because imag is not callable.
  3. Final Answer:

    imag is an attribute, not a method; parentheses cause error -> Option C
  4. Quick Check:

    imag accessed without () [OK]
Quick Trick: Access imag without parentheses to avoid errors [OK]
Common Mistakes:
  • Using imag() instead of imag
  • Confusing dtype validity
  • Assuming imag is a function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes