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.3Create a variable called
decimals and set it to 0Use
np.round() with temps and decimals to create rounded_tempsUse
np.floor() with temps to create floored_tempsUse
np.ceil() with temps to create ceiled_tempsPrint
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