0
0
NumPydata~10 mins

Integer types (int8, int16, int32, int64) 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 with 8-bit integers.

NumPy
import numpy as np
arr = np.array([1, 2, 3], dtype=[1])
print(arr.dtype)
Drag options to blanks, or click blank then click option'
Afloat32
Bint8
Cstr
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Using a float or string dtype instead of an integer type.
Forgetting to specify the dtype.
2fill in blank
medium

Complete the code to create a NumPy array with 16-bit integers.

NumPy
import numpy as np
arr = np.array([1000, 2000, 3000], dtype=[1])
print(arr.dtype)
Drag options to blanks, or click blank then click option'
Aint32
Bint8
Cint16
Dfloat64
Attempts:
3 left
💡 Hint
Common Mistakes
Using int8 which is too small for these values.
Using floating point types instead of integer types.
3fill in blank
hard

Fix the error in the code to create a 32-bit integer array.

NumPy
import numpy as np
arr = np.array([100000, 200000, 300000], dtype=[1])
print(arr.dtype)
Drag options to blanks, or click blank then click option'
Aint32
Bint8
Cint16
Dfloat32
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing int8 or int16 which cause overflow.
Using floating point types unnecessarily.
4fill in blank
hard

Fill both blanks to create a NumPy array with 64-bit integers and print its type.

NumPy
import numpy as np
arr = np.array([[1]], dtype=[2])
print(arr.dtype)
Drag options to blanks, or click blank then click option'
A10000000000
Bint8
Cint64
D500
Attempts:
3 left
💡 Hint
Common Mistakes
Using a small integer value that fits smaller types.
Using int8 which cannot hold large numbers.
5fill in blank
hard

Fill all four blanks to create a dictionary mapping integer types to their bit sizes.

NumPy
int_sizes = { '[1]': [2], '[3]': [4] }
Drag options to blanks, or click blank then click option'
Aint8
B8
Cint16
D16
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up bit sizes for integer types.
Using incorrect keys or values.