Forum Message

 

 

We have moved the forum to https://forum.ngsolve.org . This is an archived version of the topics until 05/05/23. All the topics were moved to the new forum and conversations can be continued there. This forum is just kept as legacy to not invalidate old links. If you want to continue a conversation just look for the topic in the new forum.

Notice

The forum is in read only mode.

Element-wise vector multiplication

More
1 year 8 months ago #4486 by mptino
Hello,

I have been trying for a while now to multiply two basevector objects element-wise, and cannot figure it out.

I essentially have a vector d of type basevector. I want to multiply this vector by another basevector (or even regular vectorD) element wise. I don't see a transpose for vector objects, so I can't do d = d * d (this is invalid). 

Also, any idea of how to convert a vectorD object to a basevector? I know if we have, say, d as type basevector. I can do d.FV() to get a flatvector (or vectorD) object. But how to go from flatVector to basevector is unknown...

Any suggestions?

Thanks,
Matthew
More
1 year 8 months ago #4487 by joachim
You can wrap a BaseVector into a diagonal matrix (derived from BaseMatrix), and do a matrix-vector multiplication:

from ngsolve import *
x = BaseVector(5)
y = BaseVector(5)
z = BaseVector(5)
x[:] = 2
y[:] = 5
mx = DiagonalMatrix(x)
z[:] = mx * y
print (z)


Joachim


 
Time to create page: 0.153 seconds