This gives the expected result
x = random.rand(1) + random.rand(1)*1j
print x.dtype
print x, x.real, x.imag
and this works
C = zeros((2,2),dtype=complex)
C[0,0] = 1+1j
print C
but if we change it to
C[0,0] = 1+1j + x
I get "TypeError: can't convert complex to float".
If we now omit the explicit dtype = complex
, I get "ValueError: setting an array element with a sequence".
Can someone explain what's going on, and how to do this without errors? I'm lost.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…