Using lambda in .where() #10789
Answered
by
keewis
ste-goldstein
asked this question in
Q&A
Using lambda in .where()
#10789
-
I came across this: ndvi_stack = ndvi_stack.where(lambda ndvi_stack: ndvi_stack < 0.92, 0.92)
ndvi_stack = ndvi_stack.where(lambda ndvi_stack: ndvi_stack > -0.08) Is this the same as: ndvi_stack = ndvi_stack.where(ndvi_stack < 0.92, 0.92)
ndvi_stack = ndvi_stack.where(ndvi_stack > -0.08) and if yes, why should I use one over the other ? |
Beta Was this translation helpful? Give feedback.
Answered by
keewis
Sep 25, 2025
Replies: 1 comment 2 replies
-
passing a callable is roughly equivalent to f = lambda x: x < 0.92
ndvi_stack.where(f(ndvi_stack), 0.92) This allows code like this to work: ndvi_stack.where(lambda x: x <0.92, 0.92).where(lambda x: x > -0.08) In the example you gave there's not really a good reason to use a callable since you're not chaining method calls or renaming variables. |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
ste-goldstein
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
passing a callable is roughly equivalent to
This allows code like this to work:
In the example you gave there's not really a good reason to use a callable since you're not chaining method calls or renaming variables.