human
I am working on the file "Data Science From Scratch/8 - Gradient Descent.ipynb".
The first task is:
Some step sizes provide invalid inputs to our function so we will need a safe version:
Can you write Python program for it?
 ... Write me a the Python program you requested?
assistant
#Here is the Python program you requested.

def safe(f):
    """return a new function that's the same as f,
    except that it outputs infinity whenever f produces an error"""
    def safe_f(*args, **kwargs):
        try:
            return f(*args, **kwargs)
        except:
            return float('inf') # this means "infinity" in Python
    return safe_f