Challenge - 5 Problems
Integer Types Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of numpy int8 overflow behavior
What is the output of this code snippet using numpy int8 type?
NumPy
import numpy as np x = np.array([127], dtype=np.int8) y = x + 1 print(y[0])
Attempts:
2 left
💡 Hint
Remember that int8 can only hold values from -128 to 127 and wraps around on overflow.
✗ Incorrect
Adding 1 to the maximum int8 value 127 causes overflow and wraps around to -128.
❓ data_output
intermediate2:00remaining
Size in bytes of different numpy integer types
What is the output of this code showing the itemsize of numpy integer types?
NumPy
import numpy as np sizes = {t: np.dtype(t).itemsize for t in ['int8', 'int16', 'int32', 'int64']} print(sizes)
Attempts:
2 left
💡 Hint
Itemsize is the number of bytes used to store each integer type.
✗ Incorrect
int8 uses 1 byte, int16 uses 2 bytes, int32 uses 4 bytes, and int64 uses 8 bytes.
🔧 Debug
advanced2:00remaining
Identify the error in numpy int16 overflow addition
What error will this code raise when adding two numpy int16 arrays?
NumPy
import numpy as np x = np.array([32767], dtype=np.int16) y = np.array([1], dtype=np.int16) z = x + y print(z[0])
Attempts:
2 left
💡 Hint
Check how numpy handles overflow for fixed-size integer types.
✗ Incorrect
Numpy does not raise an error on overflow for fixed-size integers; it wraps around.
🧠 Conceptual
advanced2:00remaining
Range of values for numpy int32 type
What is the correct range of values that a numpy int32 type can represent?
Attempts:
2 left
💡 Hint
int32 is a signed 32-bit integer.
✗ Incorrect
Signed 32-bit integers range from -2^31 to 2^31 - 1.
🚀 Application
expert2:00remaining
Choosing the smallest numpy integer type for given data
You have a dataset with integer values ranging from -100 to 100. Which numpy integer type is the most memory efficient to store this data without overflow?
Attempts:
2 left
💡 Hint
Check the range of int8 and uint8 types.
✗ Incorrect
int8 can store values from -128 to 127, which covers -100 to 100 safely.