0
0
NumPydata~15 mins

np.round(), np.floor(), np.ceil() in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Using np.round(), np.floor(), and np.ceil() with NumPy Arrays
📖 Scenario: Imagine you work at a weather station. You have temperature readings with decimals, but you need to prepare reports with rounded, floored, and ceiled values for different uses.
🎯 Goal: You will create a NumPy array of temperature readings, then use np.round(), np.floor(), and np.ceil() to transform these readings for reporting.
📋 What You'll Learn
Create a NumPy array called temps with exact values: 23.7, 18.2, 30.9, 15.5, 21.3
Create a variable called decimals and set it to 0
Use np.round() with temps and decimals to create rounded_temps
Use np.floor() with temps to create floored_temps
Use np.ceil() with temps to create ceiled_temps
Print rounded_temps, floored_temps, and ceiled_temps each on a separate line
💡 Why This Matters
🌍 Real World
Weather stations and many scientific fields often need to round measurements for reports or analysis. Knowing how to round numbers up, down, or to the nearest value helps prepare data correctly.
💼 Career
Data scientists and analysts frequently clean and prepare data using rounding functions to simplify numbers or meet reporting standards.
Progress0 / 4 steps
1
Create the temperature array
Import NumPy as np and create a NumPy array called temps with these exact values: 23.7, 18.2, 30.9, 15.5, 21.3
NumPy
Need a hint?

Use np.array() to create the array with the exact numbers inside square brackets.

2
Set the decimals variable
Create a variable called decimals and set it to 0 to specify rounding to whole numbers
NumPy
Need a hint?

Just assign 0 to the variable decimals.

3
Apply rounding, flooring, and ceiling
Use np.round() with temps and decimals to create rounded_temps. Use np.floor() with temps to create floored_temps. Use np.ceil() with temps to create ceiled_temps
NumPy
Need a hint?

Use the three NumPy functions exactly as shown with the correct variables.

4
Print the results
Print rounded_temps, floored_temps, and ceiled_temps each on its own line
NumPy
Need a hint?

Use three print() statements, one for each array.