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.

Complex vector operations, absolute value & phase

More
5 years 4 days ago #1545 by NilsHM
Hi!

I am working with complex vectors.
Is there any fast way to get the element wise absolute value and phase of the vector entries?
Getting the real and imaginary values with vector.real and vector.imag is helpful but I could not find such functions for the absolute or phase.

Thank You
More
5 years 4 days ago - 5 years 4 days ago #1547 by christopher
You can use numpy for that. You can get a view of the vector as a numpy array by
Code:
vec.FV().NumPy()
Best
Christopher
Last edit: 5 years 4 days ago by christopher.
The following user(s) said Thank You: NilsHM
More
5 years 4 days ago #1551 by NilsHM
Hi Christopher.

Thank you. Using numpy for complex vector operations is useful.
But is there a way to convert numpy vectors back into a GridFunction so I can plot results onto the mesh?

Best regards,
Nils
More
5 years 4 days ago #1552 by christopher
You can assign to that vector as well:
Code:
npvec = gf.vec.FV().NumPy() npvec[:] = some_array
Best
Christopher
The following user(s) said Thank You: NilsHM
Time to create page: 0.153 seconds