Python逆复数数组
我有一些带有复数值的方阵,想求逆 如果我尝试:Python逆复数数组,python,numpy,matrix,numpy-ndarray,matrix-inverse,Python,Numpy,Matrix,Numpy Ndarray,Matrix Inverse,我有一些带有复数值的方阵,想求逆 如果我尝试: (my_matrix)**(-1) import numpy as np np.linalg.inv(my_matrix) 我得到: ZeroDivisionError: 0.0 to a negative or complex power TypeError: No loop matching the specified signature and casting was found for ufunc inv 如果我尝试: (my_ma
(my_matrix)**(-1)
import numpy as np
np.linalg.inv(my_matrix)
我得到:
ZeroDivisionError: 0.0 to a negative or complex power
TypeError: No loop matching the specified signature and casting was found for ufunc inv
如果我尝试:
(my_matrix)**(-1)
import numpy as np
np.linalg.inv(my_matrix)
我得到:
ZeroDivisionError: 0.0 to a negative or complex power
TypeError: No loop matching the specified signature and casting was found for ufunc inv
如何反转复杂数组?您不能严格使用python来处理矩阵和分析数组。我建议使用Pandas或Numpy,它们是易于使用的库,可以解决您的问题。从讨论中发布的示例()中,我能够重新创建一个(4,4)复杂的数据类型数组(需要一些繁琐的编辑):
scipy.linalg.inv
做同样的事情
In [505]: x.dtype
Out[505]: dtype('complex128')
In [506]: x.shape
Out[506]: (4, 4)
使用对象数据类型:
产生错误:
In [512]: np.linalg.inv(x.astype(object))
Traceback (most recent call last):
File "<ipython-input-512-615f0ffc3570>", line 1, in <module>
np.linalg.inv(x.astype(object))
File "<__array_function__ internals>", line 5, in inv
File "/usr/local/lib/python3.8/dist-packages/numpy/linalg/linalg.py", line 545, in inv
ainv = _umath_linalg.inv(a, signature=signature, extobj=extobj)
TypeError: No loop matching the specified signature and casting was found for ufunc inv
In [513]: x.astype(object)**-1
Traceback (most recent call last):
File "<ipython-input-513-65fe9688f840>", line 1, in <module>
x.astype(object)**-1
ZeroDivisionError: 0.0 to a negative or complex power
[512]中的:np.linalg.inv(x.astype(object))
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
np.linalg.inv(x.astype(对象))
文件“”,第5行,在inv中
文件“/usr/local/lib/python3.8/dist-packages/numpy/linalg/linalg.py”,第545行,在inv中
ainv=_umath_linalg.inv(a,签名=签名,EXPRESTBJ=EXPRESTBJ)
TypeError:找不到与ufunc inv的指定签名和强制转换匹配的循环
在[513]中:x.astype(object)**-1
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
x、 A类型(对象)**-1
ZeroDivisionError:0.0为负幂或复数幂
您能展示一个吗?您不能简单地使用python来处理矩阵。你可以用熊猫。请告诉我们有关该阵列的更多信息shape
、dtype
,以及一些值(如果不是太大,则全部值)x**-1
是元素除法,除非x
是np.matrix
。显然my_matrix
不是numpy数组或矩阵
,或者如果是,则其数据类型不是数字类型。什么是类型(我的矩阵)
?如果它是一个numpy数组或矩阵,那么什么是my_matrix.dtype
?我使用numpy,但它不起作用。虽然numpy起作用,但我使用了它,它对我起作用。我想如果你用numpySo做的话,你需要使用其他的库。你用复数值反数组?半复数,它会工作的。我用Jupyter笔记本我也用Jupyter