0

I am trying to get the real values of a complex valued matrix.

import mpmath as mp
A = mp.matrix([[1+1j, 2+2j],[3+2j, 4+2j]])

I've tried both:

mp.re(A)
np.real(A)

but neither work.

I've also tried looking for information here but haven't found anything http://docs.sympy.org/0.6.7/modules/mpmath/basics.html

The first gives an error message: cannot create mpf from matrix ...

The second gives: insufficient indices for matrix

any help appreciated

evan54
  • 3,585
  • 5
  • 34
  • 61

2 Answers2

3

Just if anybody else is wondering: The easiest way to loop through the matrix is using the apply function of a mp.matrix.

import mpmath as mp

X = mp.matrix([[1+10j, 2+20j],[3+30j, 4+40j]])
real = X.apply(mp.re)
imag = X.apply(mp.im)
Benjamin
  • 206
  • 1
  • 5
2

mp.re(A[0,0]), mp.re(A[0,1]),mp.re(A[1,0]), and mp.re(A[1,1]) all work, but you are right that mp.re(A) doesn't work. For the time being you can loop through the matrix until you find a vectorized solution.

Dan Oberlam
  • 2,435
  • 9
  • 36
  • 54
user3654387
  • 2,240
  • 4
  • 19
  • 20