Bird
0
0

Which of the following is the correct way to create a NumPy array with float32 type?

easy📝 Syntax Q12 of 15
NumPy - Array Data Types
Which of the following is the correct way to create a NumPy array with float32 type?
Anp.array([1.0, 2.0], dtype='float32')
Bnp.array([1.0, 2.0], type='float32')
Cnp.array([1.0, 2.0], dtype=float16)
Dnp.array([1.0, 2.0], float='float32')
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct parameter for data type in np.array

    The correct parameter is dtype, not type or float.
  2. Step 2: Check correct dtype value for float32

    Using dtype='float32' is correct syntax to specify float32 type.
  3. Final Answer:

    np.array([1.0, 2.0], dtype='float32') -> Option A
  4. Quick Check:

    Use dtype='float32' in np.array [OK]
Quick Trick: Use dtype='float32' to set float type in np.array [OK]
Common Mistakes:
  • Using 'type' instead of 'dtype'
  • Passing float='float32' parameter
  • Using wrong dtype like float16 when asked for float32

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes