[Numpy-discussion] ScientificPython with NumPy
konrad.hinsen at laposte.net
konrad.hinsen at laposte.net
Sat Nov 25 04:20:40 CST 2006
On 25.11.2006, at 06:17, Sebastian Haase wrote:
> Just out of curiosity: Can I ask what is special about a
> Geometry.Vector ? What is the difference to a normal numpy array ?
1) A Vector always has exactly three elements of type "float".
2) A Vector is immutable.
3) Only addition and substraction work like for an array, i.e.
elementwise.
Multiplication between vectors is the dot product, division is an
error.
4) A Vector has additional methods: length, normal, cross,
dyadicProduct, angle.
Implementationwise, a vector object has a smaller memory footprint
than an array object, at least since I reimplemented Vector in Pyrex
a while ago.
So why would one want to use a special Vector object rather than an
array of shape (3,)?
1) Readability: the intention of the programmer is much clearer.
2) The additional methods are quite useful.
3) Safeguarding against mistakes: with arrays, additional checks for
shape and element size would be needed to make code robust.
4) Performance (especially memory-wise).
Konrad.
--
---------------------------------------------------------------------
Konrad Hinsen
Centre de Biophysique Moléculaire, CNRS Orléans
Synchrotron Soleil - Division Expériences
Saint Aubin - BP 48
91192 Gif sur Yvette Cedex, France
Tel. +33-1 69 35 97 15
E-Mail: hinsen at cnrs-orleans.fr
---------------------------------------------------------------------
More information about the Numpy-discussion
mailing list