Is it normal to have different results between: Using a lambda expression And using def function To express constraints with scipy optimizer I ll add code later
Asked
Active
Viewed 100 times
0
-
Lambda and first class functions not equivalent, for instance the latter have closure the former do not. – Learning is a mess Dec 02 '21 at 10:21
-
Any documentation? Thanks – user11966723 Dec 02 '21 at 10:52
-
https://stackoverflow.com/questions/2295290/what-do-lambda-function-closures-capture has a lot of insights, don't know about a proper documentation page – Learning is a mess Dec 02 '21 at 10:58
-
Share your code and we can look at your specific case. – Learning is a mess Dec 02 '21 at 10:59
-
1If the functon/lambda depends only on the passed arguments, they should be the same. But if they use a some additional variable that you expect to define either a definition time or runtime, you could run into problems. e.g. `lambda x: x+i`, what `i` is being used? – hpaulj Dec 02 '21 at 17:07
1 Answers
0
They should be identical unless you're (ab)using somewhat esoteric language features, e.g. pulling variables from outer scopes.
So most likely, there's an issue in your code.

ev-br
- 24,968
- 9
- 65
- 78