mmv
mmv

Reputation: 11

can't convert complex to float in python

here is a part of my code:

import math
import numpy as np

M_Matrix = []
for i in range(0, layer + 1):
    # creat phase retardation tilda matrix
    M = [[math.exp(-1j * phase_retardation_tilda[i]), 0],
         [0, math.exp(1j * phase_retardation_tilda[i])]]
    N = (1 / (2 * n_tilda[i+1] * a_mn[i])) * [[n_tilda[i+1] + n_tilda[i], n_tilda[i+1] - n_tilda[i]],
                                              [n_tilda[i+1] - n_tilda[i], n_tilda[i+1] + n_tilda[i]]]
    matrix = np.dot(M, N)
    M_Matrix.append(matrix)

I receive this error:

   M = [[math.exp(-1j * phase_retardation_tilda[i]), 0],
   TypeError: can't convert complex to float

what should i do with this?

Upvotes: 1

Views: 1167

Answers (1)

rchome
rchome

Reputation: 2723

From the documentation: The math module cannot be used with complex numbers; use the functions of the same name from the cmath module if you require support for complex numbers. You can use cmath.exp() instead of math.exp() in your case.

Upvotes: 1

Related Questions