Using np.vectorize() for Custom Functions
📖 Scenario: Imagine you have a list of temperatures in Celsius from different cities. You want to convert all these temperatures to Fahrenheit using a custom formula.
🎯 Goal: You will create a custom function to convert Celsius to Fahrenheit, then use np.vectorize() to apply this function to a list of temperatures efficiently.
📋 What You'll Learn
Create a list of Celsius temperatures called
celsius_temps with the values 0, 20, 37, 100Create a custom function called
c_to_f that converts Celsius to Fahrenheit using the formula F = C * 9/5 + 32Use
np.vectorize() to apply c_to_f to celsius_temps and store the result in fahrenheit_tempsPrint the
fahrenheit_temps array💡 Why This Matters
🌍 Real World
Scientists and engineers often need to apply custom calculations to many data points quickly. Vectorizing functions helps speed up these operations.
💼 Career
Data scientists and analysts use vectorized operations to handle large datasets efficiently without writing slow loops.
Progress0 / 4 steps