scipy.linalg.solve
(numpy.linalg.solve
也失败)可以处理的最大大小是否可以处理?
我正在努力将一些Matlab代码(一些poisson图像克隆,我没写过)移植到python中,而在Python中我有代码:
print M.shape
print b.shape
x = scipy.linalg.solve(M,b)
继续返回输出(和错误):
(2550, 2550)
(2550, 1)
Traceback (most recent call last):
File "D:\Other\WB_Lab\PythonPort\FaceManip\Code\test_runner.py", line 19, in <module>
ibgFaceManipulator.main(testOut,pathName,ptsFile,subjectId,'2','0')
File "D:\Other\WB_Lab\PythonPort\FaceManip\Code\ibgFaceManipulator.py", line 70, in main
ManipulateFaceWrapper.main(outDir,subjectId,retry,attempts,listchoice,NewImageData,AllBlend,Patchizer)
File "D:\Other\WB_Lab\PythonPort\FaceManip\Code\ManipulateFaceWrapper.py", line 31, in main
ManipulateFace.main(outdir,newImageData,3,filename,patchizer,blendParam,eyeDistortionParams,mouthDistortionParams,[])
File "D:\Other\WB_Lab\PythonPort\FaceManip\Code\ManipulateFace.py", line 38, in main
FaceTex = PatchOverFaceWithSelectionPre.main(TexLib,FaceTex,OperationMaskNew,M,0)
File "D:\Other\WB_Lab\PythonPort\FaceManip\Code\PatchOverFaceWithSelectionPre.py", line 104, in main
tex = poissonImageCloneColor.main(tex,source_tex,imgProc.imerode(imMask,imgProc.strel('disk',1)))
File "D:\Other\WB_Lab\PythonPort\FaceManip\Code\poissonImageCloneColor.py", line 22, in main
imr = poissonImageClone.main(imir, imr,imMask)
File "D:\Other\WB_Lab\PythonPort\FaceManip\Code\poissonImageClone.py", line 81, in main
x = scipy.linalg.solve(np.squeeze(M),b)
File "C:\Python27\lib\site-packages\scipy\linalg\basic.py", line 78, in solve
raise ValueError('expected square matrix')
ValueError: expected square matrix
但我确定M是正方形(大小为2550,2550
)。 M和b都是dtype float64,M是csc格式的矩阵。
之前有没有人见过类似的错误?
我发现numpy.linalg.cond(M)
也失败了。这一次说矩阵M是0维的(这是numpy.linalg.solve
给出的相同错误)。
答案 0 :(得分:2)
我做了一些研究,发现稀疏矩阵(我正在使用)实际上是一个特例。 Scipy为他们scipy.sparse.linalg.spsolve提供了不同的求解函数。使用这个我能够解决方程式并获得结果。
答案 1 :(得分:0)
import numpy as np
from scipy.linalg import solve
M = np.eye(5)
b = np.ones(5)
solve(M, b)
看问题是否仍然存在?而且,你的scipy版本是什么版本?