Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help unwinding assignment
#1
I am trying to understand the operation of this assignment function:

 Iss = (0.0 < tNow < 2.0) * Iin + (tNow >= 2.0 or tNow < 0) * 0 


Can anyone help me understand this:
Reply
#2
Not surprised that you don't understand it since it doesn't make any sense.

This is True if tNow > 0 and tNow < 2, else it is False
(0.0 < tNow < 2.0)
That result is multipled by Iin which is a float. When multiplying a boolean by a float, True = 1 and False = 0, so this is either Iin or 0.0 depending on the value of tNow.
(0.0 < tNow < 2.0) * Iin
Now for the makes no sense part. 0 * 0 == 0 and 1 * 0 == 0, so this is always zero.
(tNow >= 2.0 or tNow < 0) * 0
Which means these are equivalent:
Iss = (0.0 < tNow < 2.0) * Iin + (tNow >= 2.0 or tNow < 0) * 0
Iss = (0.0 < tNow < 2.0) * Iin
Which I think is easier to understand as:
Iss = Iin if (0.0 < tNow < 2.0) else 0
Reply
#3
Thanks for the help. I cut the Python code into the application, and it still worked great.
I'm attempting to translate a Python-based neuron simulator to Delphi, my development language of choice, so the Delphi result might be interesting to you:
if ((0 < tNow) AND (tNow < 2)) then
      Iss := Iin
    else
      Iss := 0;
Really quite simple when understood correctly.

... Jim
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020