Bird
0
0

Which of the following is the correct way to check broadcasting compatibility of shapes (2, 3) and (3,) using NumPy?

easy📝 Syntax Q12 of 15
NumPy - Broadcasting
Which of the following is the correct way to check broadcasting compatibility of shapes (2, 3) and (3,) using NumPy?
Anumpy.broadcast_shapes((2, 3), (3,))
Bnumpy.broadcast((2, 3), (3,))
Cnumpy.broadcast_shapes([2, 3], 3)
Dnumpy.broadcast((2, 3), (3))
Step-by-Step Solution
Solution:
  1. Step 1: Identify the correct function

    NumPy provides numpy.broadcast_shapes to check shape compatibility, which takes tuples as shape arguments.
  2. Step 2: Check argument types

    numpy.broadcast_shapes((2, 3), (3,)) uses numpy.broadcast_shapes with tuples, which is correct. numpy.broadcast_shapes([2, 3], 3) uses a scalar for the second argument, which is invalid for this function.
  3. Final Answer:

    numpy.broadcast_shapes((2, 3), (3,)) -> Option A
  4. Quick Check:

    Use numpy.broadcast_shapes with tuples [OK]
Quick Trick: Use numpy.broadcast_shapes with tuples for shape check [OK]
Common Mistakes:
  • Using numpy.broadcast instead of numpy.broadcast_shapes
  • Passing scalars instead of sequences
  • Missing parentheses or wrong argument types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes