in_unit function

(Shortest import: from brian2 import in_unit)

brian2.units.fundamentalunits.in_unit(x, u, precision=None)[source]

Display a value in a certain unit with a given precision.


x : {Quantity, array-like, number}

The value to display

u : {Quantity, Unit}

The unit to display the value x in.

precision : int, optional

The number of digits of precision (in the given unit, see Examples). If no value is given, numpy’s get_printoptions() value is used.


s : str

A string representation of x in units of u.

See also



>>> from brian2 import *
>>> in_unit(3 * volt, mvolt)
'3000. mV'
>>> in_unit(123123 * msecond, second, 2)
'123.12 s'
>>> in_unit(10 * uA/cm**2, nA/um**2)
'1.00000000e-04 nA/um^2'
>>> in_unit(10 * mV, ohm * amp)
'0.01 ohm A'
>>> in_unit(10 * nS, ohm) 
Traceback (most recent call last):
DimensionMismatchError: Non-matching unit for method "in_unit",
dimensions were (m^-2 kg^-1 s^3 A^2) (m^2 kg s^-3 A^-2)