Doubt in soaplusbias

Hi,

This might be very basic question.
But I am not able to understand how we are passing (3,4)
as argument in sosplusbias because sosplusbias is function of soaplusbias which expects a function

def soaplusbias(f, bias): # sum anything
def h(x, y):
return f(x) + f(y) + bias
return h
sosplusbias = soaplusbias(lambda x: x*x, 5)
sosplusbias(3, 4)

Thanks and Regards,
Subho

Hi @subhobrata1,

A few things are happening here, so let’s break it down.

  1. soaplusbias inputs a function and value, and outputs a function h.

  2. function h inputs two values and outputs a value.

If that is clear, it should follow that sosplusbias a variation of function h, which takes two values.
hence sosplusbias(3,4) is correct and outputs f(x)+f(y) + bias = 3^2+4^2+5=30

Also, could you post code in markdown because python being indented, its important to see exactly what you’re doing. for eg. your above code will not work, but I guess you meant this

def soaplusbias(f, bias): # sum anything
    def h(x, y):
        return f(x) + f(y) + bias
    return h

sosplusbias = soaplusbias(lambda x: x*x, 5)

sosplusbias(3, 4)
2 Likes

Thanks will check this out