0
0
NumPydata~5 mins

np.round(), np.floor(), np.ceil() in NumPy - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does np.round() do in numpy?

np.round() rounds each number in an array to the nearest integer or to a specified number of decimal places.

Click to reveal answer
beginner
Explain the function of np.floor().

np.floor() takes each number in an array and rounds it down to the nearest whole number (integer) less than or equal to the number.

Click to reveal answer
beginner
What does np.ceil() do?

np.ceil() rounds each number in an array up to the nearest whole number (integer) greater than or equal to the number.

Click to reveal answer
intermediate
How does np.round() differ from np.floor() and np.ceil()?

np.round() rounds to the nearest integer (up or down), while np.floor() always rounds down and np.ceil() always rounds up.

Click to reveal answer
beginner
If you have the number 3.7, what will np.round(), np.floor(), and np.ceil() return?

np.round(3.7) returns 4.0<br>np.floor(3.7) returns 3.0<br>np.ceil(3.7) returns 4.0

Click to reveal answer
What does np.floor(2.9) return?
A2.9
B3.0
C2.0
D3.9
Which function rounds numbers to the nearest integer, either up or down?
Anp.round()
Bnp.floor()
Cnp.ceil()
DNone of these
What will np.ceil(-1.2) return?
A-2.0
B-0.0
C-1.2
D-1.0
How can you round numbers in a numpy array to 2 decimal places?
Anp.round(array, 2)
Bnp.floor(array, 2)
Cnp.ceil(array, 2)
Dnp.round(array)
Which function always rounds numbers up?
Anp.floor()
Bnp.ceil()
Cnp.round()
Dnp.trunc()
Describe the difference between np.round(), np.floor(), and np.ceil() with examples.
Think about how each function treats decimals differently.
You got /4 concepts.
    Explain how you would round all numbers in a numpy array to 1 decimal place using numpy functions.
    Look for a function that allows decimal precision.
    You got /3 concepts.