installation: either run:
easy_install vop
or download here: vop-1.2.1.tar.gz
vop is a Python module that supports a simple set of operators on one-dimensional vectors of floating-point numbers. It is styled after Numeric, but offers nowhere near Numeric's capabilities. vop has a significant edge in speed: on some tasks it is 7X faster than Numeric.
$ ./try.py 300000000 operations took 0.387395s, 774.403576 megaflops $ ./try_numeric.py 300000000 operations took 3.237142s, 92.674345 megaflops |
Here are some examples of what vop can do:
>>> import vop >>> a = vop.arange(10) >>> print a.tolist() [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0] >>> print (a + 100).tolist() [100.0, 101.0, 102.0, 103.0, 104.0, 105.0, 106.0, 107.0, 108.0, 109.0] >>> print (a * a).tolist() [0.0, 1.0, 4.0, 9.0, 16.0, 25.0, 36.0, 49.0, 64.0, 81.0] >>> print vop.sqrt(a).tolist() [0.0, 1.0, 1.4142135381698608, 1.7320507764816284, 2.0, 2.2360680103302002, 2.4494898319244385, 2.6457512378692627, 2.8284270763397217, 3.0] >>> |
(a + 100) means that
the additon operator adds the scalar value 100 to every element of
the vector a. This is the same behavior as Numeric, and means that you can use the same code for scalar arithmetic as handling vops.
For example, this function:
def pythagoras(a, b):
return sqrt((a * a) + (b * b))
|
a[b].
Similar to Numeric's 'take' operator, but allows either argument to be a scalar.
p ? a : b.
Similar to Numeric's 'where' operator, but allows any argument to be a scalar.