0
0
NumPydata~10 mins

np.round(), np.floor(), np.ceil() 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 round the values in the array to the nearest integer.

NumPy
import numpy as np
arr = np.array([1.2, 2.5, 3.7])
rounded = np.[1](arr)
print(rounded)
Drag options to blanks, or click blank then click option'
Aceil
Bround
Cfloor
Dabs
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.floor or np.ceil instead of np.round
Forgetting to import numpy
2fill in blank
medium

Complete the code to get the largest integer less than or equal to each element in the array.

NumPy
import numpy as np
arr = np.array([1.2, 2.5, 3.7])
floored = np.[1](arr)
print(floored)
Drag options to blanks, or click blank then click option'
Aabs
Bround
Cceil
Dfloor
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.ceil instead of np.floor
Confusing floor with round
3fill in blank
hard

Fix the error in the code to get the smallest integer greater than or equal to each element.

NumPy
import numpy as np
arr = np.array([1.2, 2.5, 3.7])
ceiled = np.[1](arr)
print(ceiled)
Drag options to blanks, or click blank then click option'
Afloor
Babs
Cceil
Dround
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.floor instead of np.ceil
Using np.round instead of np.ceil
4fill in blank
hard

Fill both blanks to create a dictionary with words as keys and their lengths rounded down if length is greater than 3.

NumPy
import numpy as np
words = ['apple', 'bat', 'carrot', 'dog']
lengths = {word: np.[1](len(word)) for word in words if len(word) [2] 3}
print(lengths)
Drag options to blanks, or click blank then click option'
Afloor
B>
C<=
Dround
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.round instead of np.floor
Using <= instead of > in the condition
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase words as keys and their lengths rounded up if length is less than 5.

NumPy
import numpy as np
words = ['apple', 'bat', 'carrot', 'dog']
lengths = {word.[1](): np.[2](len(word)) for word in words if len(word) [3] 5}
print(lengths)
Drag options to blanks, or click blank then click option'
Aupper
Bceil
C<
Dfloor
Attempts:
3 left
💡 Hint
Common Mistakes
Using floor instead of ceil for rounding
Using > instead of < in the condition
Forgetting to convert words to uppercase