On 7/5/12 11:53 PM, Peng Yu wrote:
On Thu, Jul 5, 2012 at 1:57 PM, John H Palmieri <[email protected]> wrote:


On Thursday, July 5, 2012 11:48:27 AM UTC-7, Peng Yu wrote:

I don't find a convenient way for doing element wise product of vectors.
Is there an operator for it? (or less cumbersome way)


sage: v = vector([1,2,3])
sage: v.pairwise_product(v)
(1, 4, 9)


Is that what you want?

Is there also a convenient way for elementwise divide?


No, but you can do it and many other operations like this:

u = vector([1,2,3])
v = vector([6,5,4])
vector([i/j for i,j in zip(u,v)])

If you use numpy arrays, the operations are all element-wise:

from numpy import array
sage: u=array([1.0,2.0,3.0])
sage: v=array([5.0,4.0,3.0])
sage: u/v
array([ 0.2,  0.5,  1. ])


I wonder if you'd have a more natural time working with numpy arrays.

Thanks,

Jason

--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to