0
0
NumPydata~20 mins

np.round(), np.floor(), np.ceil() in NumPy - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Rounding Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of np.round() with decimals parameter
What is the output of this code snippet?
NumPy
import numpy as np
arr = np.array([1.234, 2.345, 3.456])
result = np.round(arr, decimals=1)
print(result)
A[1.23 2.35 3.46]
B[2.0 2.0 3.0]
C[1.0 2.0 3.0]
D[1.2 2.3 3.5]
Attempts:
2 left
💡 Hint
np.round rounds each element to the specified number of decimal places.
Predict Output
intermediate
2:00remaining
Output of np.floor() on negative and positive values
What is the output of this code?
NumPy
import numpy as np
arr = np.array([-1.7, -0.2, 0.2, 1.7])
result = np.floor(arr)
print(result)
A[-1. -0. 0. 1.]
B[-2. -1. 0. 1.]
C[-1. -1. 0. 1.]
D[-2. -1. 1. 2.]
Attempts:
2 left
💡 Hint
np.floor returns the largest integer less than or equal to each element.
Predict Output
advanced
2:00remaining
Output of np.ceil() with mixed values
What does this code print?
NumPy
import numpy as np
arr = np.array([1.1, 2.5, 3.0, -1.1, -2.5])
result = np.ceil(arr)
print(result)
A[ 2. 3. 3. -1. -3.]
B[ 1. 3. 3. -2. -3.]
C[ 1. 2. 3. -1. -2.]
D[ 2. 3. 3. -1. -2.]
Attempts:
2 left
💡 Hint
np.ceil returns the smallest integer greater than or equal to each element.
Predict Output
advanced
2:00remaining
Number of elements after rounding and filtering
How many elements are in the array after rounding to 0 decimals and filtering values > 2?
NumPy
import numpy as np
arr = np.array([1.9, 2.1, 2.5, 3.4, 1.2])
rounded = np.round(arr, decimals=0)
filtered = rounded[rounded > 2]
print(len(filtered))
A4
B2
C1
D3
Attempts:
2 left
💡 Hint
Round first, then count how many are greater than 2.
🧠 Conceptual
expert
3:00remaining
Understanding behavior of np.round() with negative decimals
What is the output of this code snippet?
NumPy
import numpy as np
arr = np.array([123.45, 678.91, 234.56])
result = np.round(arr, decimals=-1)
print(result)
A[120. 680. 230.]
B[123. 679. 235.]
C[100. 600. 200.]
D[130. 680. 240.]
Attempts:
2 left
💡 Hint
Negative decimals rounds to the left of the decimal point.