Skip to content

Convert boolean in float #22289

Answered by redeboer
Simone2021space asked this question in Q&A
Discussion options

You must be logged in to vote

Sounds like you are looking for Piecewise:

>>> import sympy as sp
>>> z = sp.Symbol("z")
>>> expr = sp.Piecewise(
...     (z, z < 0.1),
...     (1.0, True),
... )
>>> expr.subs(z, .05)
0.05
>>> expr.subs(z, 2)
1.0

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by Simone2021space
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants