[Numpy-discussion] vector cross product
David M. Cooke
cookedm at physics.mcmaster.ca
Tue Nov 2 20:54:47 CST 2004
"Gary Ruben" <gazzar at email.com> writes:
> I guess from the lack of enthusiastic responses that there aren't
> many out there who think this is of interest. So, perhaps Todd could
> just add it to the bottom of the list of possible ideas I imagine he
> maintains, so that if it comes up again in the future, it is at
> least noted. thanks, Gary
If all you need is a 3-dimensional vector class, I've just whipped
one up using Pyrex. (I needed it for something else.)
It just does 3-vectors, and it's quite similiar to Konrad Hinsen's
Vector class, although the components are referenced by attributes
(using properties) instead of methods.
Get it at
It's called the inventive name of vector3.
Here's a speed comparision:
$ timeit.py -s 'from Scientific.Geometry import Vector as V' 'V(1,2,3).angle(V(4,5,6))'
10000 loops, best of 3: 40.5 usec per loop
$ timeit.py -s 'from vector3 import Vector3 as V' 'V(1,2,3).angle(V(4,5,6))'
1000000 loops, best of 3: 1.87 usec per loop
[I'm also working on an n-dimensional vector class using Pyrex, more
along the lines of a 1-dimensional, contiguous, Numeric or numarray
array. Currently, it's 3x and 5.5x times faster, respectively, for
adding 1000-element vectors. I'm not ready to release it yet, though.]
> ----- Original Message -----
> From: "Gary Ruben" <gazzar at email.com>
> To: numpy-discussion at lists.sourceforge.net
> Subject: [Numpy-discussion] vector cross product
> Date: Sun, 31 Oct 2004 22:18:56 +1000
>> Not that I have a really urgent need, but is there a reason that
>> nice, fast C-based vector operations aren't implemented in Numeric
>> or numarray? I notice Fernando Perez has a cross product as a
>> useful SciPy weave example on his site. I've also seen comments
>> elsewhere about Numpy's lack of a cross product. eg.
>> I'm using Konrad Hinsen's Scientific Python for the convenience
>> value of his Vector class, which also provides a nice angle()
>> method but it bothers me that it's implemented in native Python.
>> The Vector type in vpython probably does it 'properly', but I don't
>> use it just for the convenience since it adds an extra dependency
>> to my code.
>> Gary R.
|David M. Cooke http://arbutus.physics.mcmaster.ca/dmc/
|cookedm at physics.mcmaster.ca
More information about the Numpy-discussion