How to round Quantity instances in brian2?

47 Views Asked by At

I have this problem:

equilibrium_potential = my_func()  # outputs equilibrium_potential*mV

I want to check that equilibrium_potential is around 77*mV. I've tried calling base python round on the equilibrium_potential which is of type brian2.units.fundamentalunits.Quantity so the interpreter threw an error. I also tried np.round from NumPy; the program didn't crash, but it did output 0*mV which is also not what I want. Does anyone know how to round using Brian2?

I've looked at the documentation, but it doesn't seem to provide any useful steps towards a solution.

1

There are 1 best solutions below

0
On BEST ANSWER

abs(equilibrium_potential/mV-77) < 0.1

To do something within an equation if equilibrium_potential is outside the range, you need to wrap this code by int function. Like that:

int(abs(equilibrium_potential/mV-77) < 0.1)