0
0
NumPydata~10 mins

Specifying dtype during creation in NumPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a NumPy array of integers.

NumPy
import numpy as np
arr = np.array([1, 2, 3], dtype=[1])
Drag options to blanks, or click blank then click option'
Aint
Bbool
Cstr
Dfloat
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'float' instead of 'int' changes the array to decimals.
Using 'str' creates an array of strings, not numbers.
2fill in blank
medium

Complete the code to create a NumPy array of floats.

NumPy
import numpy as np
arr = np.array([1, 2, 3], dtype=[1])
Drag options to blanks, or click blank then click option'
Aint
Bbool
Cfloat
Dcomplex
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'int' results in whole numbers only.
Using 'bool' creates True/False values, not numbers.
3fill in blank
hard

Fix the error in the code to create a NumPy array of booleans.

NumPy
import numpy as np
arr = np.array([0, 1, 2], dtype=[1])
Drag options to blanks, or click blank then click option'
Astr
Bfloat
Cint
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'int' keeps the numbers as integers.
Using 'str' converts numbers to strings.
4fill in blank
hard

Fill both blanks to create a NumPy array of complex numbers.

NumPy
import numpy as np
arr = np.array([1, 2, 3], dtype=[1])
print(arr[2])
Drag options to blanks, or click blank then click option'
Acomplex
Bint
C.dtype
D.shape
Attempts:
3 left
💡 Hint
Common Mistakes
Using '.shape' instead of '.dtype' prints the array shape, not type.
Using 'int' does not create complex numbers.
5fill in blank
hard

Fill all three blanks to create a NumPy array of strings and print its shape.

NumPy
import numpy as np
arr = np.array(["a", "b", "c"], dtype=[1])
print(arr[2])
print(arr[3])
Drag options to blanks, or click blank then click option'
Astr
B.dtype
C.shape
Dint
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'int' as dtype creates integer array, not strings.
Mixing up '.dtype' and '.shape' attributes.