Skip to content
Advertisement

Python – Using a lambda function stored in a list of functions inside a class

I’m trying to set up a Functions class that will handle functions for my NN projects. I’ve figured out I’d like the list of functions to be somewhat flexible (easily add, or remove functions used).

I’ve created a list of functions, defined a bunch of lambda functions, added a method that adds all the functions in the body to the list. When I try to check the length of the list it shows the correct number, but when I try to retrieve a function into a variable and pass it an argument I get an information that lambda takes 1 argument and I gave it 2. I don’t understand what is the second argument.

JavaScript

What’s causing the issue? Alternatively what would be a better way to have an enumerable data structure to store and load the activation functions?

Advertisement

Answer

All these functions behave the same as add_function, __init__, and number_of_functions. They are secretly being passed self. I have shown two fixes below:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement