Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
Using dtype='int' creates an integer array.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'int' results in whole numbers only.
Using 'bool' creates True/False values, not numbers.
✗ Incorrect
Using dtype='float' creates an array with decimal numbers.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'int' keeps the numbers as integers.
Using 'str' converts numbers to strings.
✗ Incorrect
Using dtype='bool' converts numbers to True/False values.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '.shape' instead of '.dtype' prints the array shape, not type.
Using 'int' does not create complex numbers.
✗ Incorrect
Use dtype='complex' to create complex numbers.
Use .dtype to print the data type of the array.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'int' as dtype creates integer array, not strings.
Mixing up '.dtype' and '.shape' attributes.
✗ Incorrect
Use dtype='str' to create an array of strings.
Use .dtype to print the data type.
Use .shape to print the array shape.