Bird
0
0

Which of the following is the correct way to create a NumPy array of integers using dtype?

easy📝 Syntax Q12 of 15
NumPy - Array Data Types
Which of the following is the correct way to create a NumPy array of integers using dtype?
Anp.array([1, 2, 3], type='int')
Bnp.array([1, 2, 3], dtype='int')
Cnp.array([1, 2, 3], dtype=int32)
Dnp.array([1, 2, 3], dtype='string')
Step-by-Step Solution
Solution:
  1. Step 1: Check correct dtype syntax

    The correct parameter is dtype with a string like 'int' or a NumPy dtype like np.int32.
  2. Step 2: Evaluate each option

    np.array([1, 2, 3], dtype='int') uses dtype='int' which is valid. np.array([1, 2, 3], type='int') uses wrong parameter type. np.array([1, 2, 3], dtype=int32) uses dtype=int32 without quotes or np.int32, which causes error. np.array([1, 2, 3], dtype='string') uses dtype='string' which is valid but not integer.
  3. Final Answer:

    np.array([1, 2, 3], dtype='int') -> Option B
  4. Quick Check:

    Correct dtype syntax = A [OK]
Quick Trick: Use dtype='int' or dtype=np.int32 for integers [OK]
Common Mistakes:
  • Using 'type' instead of 'dtype'
  • Missing quotes around dtype string
  • Using wrong dtype names like 'string' for integers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NumPy Quizzes