Code is here
return self.activator(reduce(lambda a, b: a+b, map(lambda x, w: x*w, zip(input_vec, self.weights)), 0.0) + self.bias)
The python2.7-version code is like lambda (x, w)
But now the Tuple parameter unpacking was removed so I dont know how to figure it :(
It is a good thing to make a small running example which shows the problem. In your case, that is not the fact since we are missing some variables. Like i said in the other comment, your list you map over is made of tuples. Like you already know, you cannot unpack the tuples anymore, but you can use indices like you would use on an array. A simple working example:
val = reduce(lambda a, b: a+b, map(lambda t: t[0]*t[1], zip([10, 20, 30], [0.1, 0.3, 0.7])), 0.0)
print(val)
Like you see, the lambda function passed to the map function just has one parameter now. I called it t to make clear that this is a tuple, you can call it x if you want. In the function-body i use indices to get the first and second element of the tuple. If you run this code, you see that it works. So next step is to adept that to your code:
return self.activator(reduce(lambda a, b: a+b, map(lambda t: t[0]*t[1], zip(input_vec, self.weights)), 0.0) + self.bias)
And that should do the trick.
you can't unpack anymore. But, you can just take tuple as it is, and use indexing in the formula:
map(lambda t: t[0]*t[1], zip(input_vec, self.weights))
using map
with lambda
has little interest, generator comprehension equivalent:
(x*w for x,w in zip(input_vec, self.weights))
(and unpacking works)
The same construct needs to be repeated with the outer lambda
and even reduce
, which can be completely eliminated with sum
which performs sums of the elements:
return self.activator(sum(x*w for x,w in zip(input_vec, self.weights)) + self.bias)
no more lambdas, shorter and clearer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With