I have recently upgraded my SciPy stack. Ipython Notebooks that previously worked now fail in the new Jupyter Notebook.
我最近升级了我的SciPy堆栈。以前工作的Ipython笔记本现在在新的Jupyter笔记本中失败了。
Previously I could evaluate SymPy matrices using SciPy/NumPy functions. Below is a minimal example with the eig
function from SciPy performed on a SymPy matrix. It returns object arrays are not supported
. This did not used to happen. During my upgrade several packages may have upgraded, including SymPy.
以前我可以使用SciPy / NumPy函数来评估SymPy矩阵。下面是在SymPy矩阵上执行SciPy的eig函数的最小示例。它不支持返回对象数组。这不常发生。在升级期间,可能已升级了几个软件包,包括SymPy。
1 个解决方案
#1
2
I don't know how it worked in your previous setup, but the process of converting SymPy matrices to NumPy arrays was explicit as early as 2012, per this answer, and SymPy has a utility function matrix2numpy
for this purpose. So, in your context
我不知道它在你之前的设置中是如何工作的,但是早在2012年,将SymPy矩阵转换为NumPy阵列的过程是明确的,根据这个答案,SymPy为此目的有一个效用函数matrix2numpy。所以,在你的背景下
LA.eig(matrix2numpy(M, dtype=float))
returns the expected eigenvalues. Without the helper function, it could be
返回预期的特征值。没有辅助功能,它可能是
LA.eig(np.array(M.tolist(), dtype=float))
If you'd like SciPy functions to accept SymPy objects, that would be an issue for their tracker, rather than a question for Stack Overflow.
如果您希望SciPy函数接受SymPy对象,那么对于它们的跟踪器来说这将是一个问题,而不是Stack Overflow的问题。
#1
2
I don't know how it worked in your previous setup, but the process of converting SymPy matrices to NumPy arrays was explicit as early as 2012, per this answer, and SymPy has a utility function matrix2numpy
for this purpose. So, in your context
我不知道它在你之前的设置中是如何工作的,但是早在2012年,将SymPy矩阵转换为NumPy阵列的过程是明确的,根据这个答案,SymPy为此目的有一个效用函数matrix2numpy。所以,在你的背景下
LA.eig(matrix2numpy(M, dtype=float))
returns the expected eigenvalues. Without the helper function, it could be
返回预期的特征值。没有辅助功能,它可能是
LA.eig(np.array(M.tolist(), dtype=float))
If you'd like SciPy functions to accept SymPy objects, that would be an issue for their tracker, rather than a question for Stack Overflow.
如果您希望SciPy函数接受SymPy对象,那么对于它们的跟踪器来说这将是一个问题,而不是Stack Overflow的问题。