这将给出预期的结果
x = random.rand(1) + random.rand(1)*1j
print x.dtype
print x, x.real, x.imag
这个有效
C = zeros((2,2),dtype=complex)
C[0,0] = 1+1j
print C
但是如果我们将其改为
C[0,0] = 1+1j + x
我遇到了"TypeError:无法将复数转换为浮点数"的错误。
如果现在省略显式的 dtype = complex
,我会遇到"ValueError:使用序列设置数组元素"的错误。
有人能解释一下发生了什么,以及如何避免出现错误吗?我很困惑。
a=np.arange(4).reshape((2,2)); b=np.array([100]); a[0,0]=b
不会出现错误呢? - zhangxaochenC[0,0] = random.rand(1)
不应该起作用,但它确实起作用了。我仍然感到困惑。 - gibson