将numpy数组的第二列转换为虚数
我想将numpy数组的第二列转换为虚数。
尝试失败:
>>> Z = np.array([[1, 2], [3, 4], [5, 6]])
>>> print(Z)
[[1 2]
[3 4]
[5 6]]
>>> Z[:, 1] = (Z[:, 1]) * 1j
ComplexWarning: Casting complex values to real discards the imaginary part
>>> print(Z)
[[1 0]
[3 0]
[5 0]]
预期结果:
[[1+2.j]
[3+4.j]
[5+6.j]]
转载请注明出处:http://www.033230.com/article/20230401/2235094.html