[Numpy-discussion] use of %extend
Michel Dupront
michel.dupront at hotmail.fr
Thu Apr 15 05:53:44 EDT 2010
Hello,
With the following example, given in the documentation:
struct Vector {
double x,y,z;
};
%extend Vector {
Vector __add__(Vector *other) {
Vector v;
v.x = $self->x + other->x;
v.y = $self->y + other->y;
v.z = $self->z + other->z;
return v;
}
};
one can do in python:
>>> import example
>>> v = example.Vector(2,3,4)
>>> w = example.Vector(10,11,12)
>>> print v+w
Vector(12,14,16)
>>>
There is something more that I would like to do but I don't
know how. I would like to be able to do:
>>>> v1 = v + 2
>>>> v2 = 2 + v
where v is a vector and 2 a number that would be added to each component
of the vector.
I would really appreciate any help on that.
Many thanks in advance.
_________________________________________________________________
Hotmail arrive sur votre téléphone ! Compatible Iphone, Windows Phone, Blackberry, …
http://www.messengersurvotremobile.com/?d=Hotmail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20100415/a351b5b3/attachment.html>
More information about the NumPy-Discussion
mailing list