Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
难以实施Strassen';Python中的s算法_Python_Algorithm_Recursion_Runtime Error_Strassen - Fatal编程技术网

难以实施Strassen';Python中的s算法

难以实施Strassen';Python中的s算法,python,algorithm,recursion,runtime-error,strassen,Python,Algorithm,Recursion,Runtime Error,Strassen,我不明白如何递归调用我的代码。以下是我目前的代码: import numpy B = [[5,5,5,5,5,5,5,5],[6,6,6,6,6,6,6,6],[7,7,7,7,7,7,7,7],[8,8,8,8,8,8,8,8], [9,9,9,9,9,9,9,9], [10,10,10,10,10,10,10,10],[11,11,11,11,11,11,11,11], [12,12,12,12,12,12,12,12]] A = [[5,5,5,5,5,5,5,5],[6

我不明白如何递归调用我的代码。以下是我目前的代码:

import numpy

B = [[5,5,5,5,5,5,5,5],[6,6,6,6,6,6,6,6],[7,7,7,7,7,7,7,7],[8,8,8,8,8,8,8,8],
 [9,9,9,9,9,9,9,9], [10,10,10,10,10,10,10,10],[11,11,11,11,11,11,11,11],       [12,12,12,12,12,12,12,12]]

A = [[5,5,5,5,5,5,5,5],[6,6,6,6,6,6,6,6],[7,7,7,7,7,7,7,7],[8,8,8,8,8,8,8,8],
 [1,1,1,1,1,1,1,1], [2,2,2,2,2,2,2,2],[3,3,3,3,3,3,3,3],[4,4,4,4,4,4,4,4]]

def main():
   strassen(A,B)

def strassen(A, B):
    A = numpy.asarray(A)
    B = numpy.asarray(B)
    lengthA = len(A)
    lengthB = len(B)
    if lengthA == 2:
        print "will calculate"
    else:       
        a, b = strassen(A[:lengthA//2, :lengthA//2], B[:lengthB//2, :lengthB//2])

        lengthA = lengthA//2
        lengthB = lengthB//2
        print a
        print b
        return a, b
我正试图将
a
减少到
[[5,5],[6,6]]
b
减少到
[[5,5],[6,6]]
,但我得到了一个错误:

a, b = strassen(A[:lengthA//2, :lengthA//2], B[:lengthB//2, :lengthB//2])
TypeError: 'NoneType' object is not iterable. 

a
b
是在a和b的第二次整矩阵除法之后形成的第一个2x2矩阵。请有人给我解释一下。谢谢

在递归终止条件中没有返回值。当我运行代码时,它会在给出错误之前打印“将计算”。之后会发生错误,因为最后一次调用(当
lengthA==2
时)没有来自strassen函数的返回值