+ 1

Help me to compress these functions into one please

I have these two functions that are used independently for different purposes class Neural_network def __init__(self, input): self.input = input .............. def calculate(self,inp): out = self.sigmoid(dot(inp, self.weights)) return out def fire(self): self.output = self.calculate(self.input) I would like to make one function with two variants, one of which has to have no arguments. I tried setting the default value to be used when no arguments are given. def calculate(self, inp = self.input) It turned out to be impossible because I can't use "self. " syntax while defining a function. So my question is how to set that default value? P.S. i need my self.input to be unique for each object, obviously, so it didn't work when I tried just not using the "self. "

1st Jun 2018, 12:47 PM
hide on bush
hide on bush - avatar
1 Resposta
+ 1
Maybe this way you can check if there are no arguments passed, and assign a default value: def calculate(self, inp): inp = self.input if inp == None out = self.sigmoid(dot(inp, self.weights)) return out
3rd Jun 2018, 3:19 PM
Jay Dadhania
Jay Dadhania - avatar