0
0
NumPydata~15 mins

Universal functions (ufuncs) in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Using NumPy Universal Functions (ufuncs) for Array Operations
📖 Scenario: Imagine you are analyzing daily temperatures recorded over a week in Celsius. You want to quickly convert these temperatures to Fahrenheit and also find the square root of each temperature value to explore some mathematical transformations.
🎯 Goal: Build a small program that uses NumPy universal functions (ufuncs) to convert a list of temperatures from Celsius to Fahrenheit and calculate the square root of each temperature.
📋 What You'll Learn
Create a NumPy array called temps_celsius with the exact values: 0, 10, 20, 30, 40, 50, 60
Create a variable called temps_fahrenheit that converts temps_celsius to Fahrenheit using a NumPy ufunc
Create a variable called temps_sqrt that contains the square root of each temperature in temps_celsius using a NumPy ufunc
Print both temps_fahrenheit and temps_sqrt arrays
💡 Why This Matters
🌍 Real World
Scientists and engineers often use NumPy ufuncs to quickly apply mathematical operations to large datasets, such as temperature readings, sensor data, or financial numbers.
💼 Career
Understanding and using NumPy ufuncs is essential for data scientists and analysts to efficiently process and analyze numerical data in Python.
Progress0 / 4 steps
1
Create the NumPy array of temperatures in Celsius
Import NumPy as np and create a NumPy array called temps_celsius with these exact values: 0, 10, 20, 30, 40, 50, 60
NumPy
Need a hint?

Use np.array([...]) to create the array with the exact temperature values.

2
Convert Celsius to Fahrenheit using a NumPy ufunc
Create a variable called temps_fahrenheit that converts temps_celsius to Fahrenheit using the formula (temps_celsius * 9/5) + 32 with NumPy operations
NumPy
Need a hint?

Use element-wise operations on the NumPy array to convert Celsius to Fahrenheit.

3
Calculate the square root of each Celsius temperature using a NumPy ufunc
Create a variable called temps_sqrt that contains the square root of each value in temps_celsius using the NumPy np.sqrt() universal function
NumPy
Need a hint?

Use np.sqrt() to get the square root of each element in the array.

4
Print the Fahrenheit and square root arrays
Print the variables temps_fahrenheit and temps_sqrt each on its own line
NumPy
Need a hint?

Use two print() statements to display the arrays.