Numeric with units
Fernando Perez
fperez528 at yahoo.com
Fri May 16 14:15:12 EDT 2003
John Hunter wrote:
> Has anyone written some code to integrate Numeric arrays with unum, or
> another units package?
Hi John,
take a look at ScientificPython's PhysicalQuantities. It's not integrated with
Numeric, but it is a really solid units package. You might be able to do the
integration with a bit of work.
Here's a simple example, with IPython's preprocessing of the input line to give
you a really convenient 'physics calculator'. I wrote this to check student's
physics homework assignments quickly, and used it a lot:
[~]> ipython -p physics
Python 2.2.1 (#1, Aug 30 2002, 12:15:30)
Type "copyright", "credits" or "license" for more information.
IPython 0.2.15pre5 -- An enhanced Interactive Python.
? -> Introduction to IPython's features.
@magic -> Information about IPython's 'magic' @ functions.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
IPython profile: physics
*** Simplified input for physical quantities enabled.
*** q is an alias for PhysicalQuantityInteractive
*** g = 9.8 m/s^2 has been defined
*** rad = pi/180 has been defined
In [1]: mass = 3.0 kg
In [2]: weight = mass*g
In [3]: weight
Out[3]: 29.4 m*kg/s^2
In [4]: weight.
weight._number weight.cos weight.sin weight.unit
weight._sum weight.inBaseUnits weight.sqrt weight.value
weight.b weight.inUnitsOf weight.tan
weight.convertToUnit weight.isCompatible weight.u
In [4]: weight.u('N')
Out[4]: 29.4 N
More information about the Python-list
mailing list