Bird
0
0

What issue exists in this code snippet?

medium📝 Debug Q6 of 15
SciPy - Integration with Scientific Ecosystem
What issue exists in this code snippet?
from scipy import io
my_data = {'values': (1, 2, 3)}
io.savemat('output.mat', my_data)
AThe filename must include the .mat extension explicitly
BTuples are not supported; use numpy arrays instead
CThe dictionary keys must be integers, not strings
DNo issue; this code runs correctly
Step-by-Step Solution
Solution:
  1. Step 1: Check data types supported by savemat

    savemat expects values to be numpy arrays or compatible types; tuples are not supported directly.
  2. Step 2: Identify the problem

    Using a tuple as a value will cause an error or unexpected behavior; converting to a numpy array fixes this.
  3. Step 3: Confirm other options

    The filename is valid, keys must be strings, and the code will not run correctly as is.
  4. Final Answer:

    Tuples are not supported; use numpy arrays instead -> Option B
  5. Quick Check:

    savemat requires numpy arrays, not tuples [OK]
Quick Trick: Convert tuples to numpy arrays before saving [OK]
Common Mistakes:
  • Using tuples instead of arrays
  • Omitting .mat extension (optional)
  • Using non-string keys in dict

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes