我知道这个问题经常被重复,但我还没见过一个能解决这个具体问题的问题。我得到了这个函数,它取numpy数组的长度,然后取叉积:
def solve(tab, vacios):
if vacios == 0:
return is_valid( tab ) #Not important here
large = len(tab)
for fila, col in product(range(large), repeat=(large-1)):
但我得到一个错误:
^{pr2}$我真的不知道该怎么办,所以如果你能帮我,那就太好了,谢谢!在
每次迭代都会产生一个
large-1
值的组合,因为这就是您将repeat
参数设置为:但是将值解压为两个变量
^{pr2}$fila
和col
:如果传入一个长度不是3的
tab
值,那么要解包的值的数目总是错误的。在例如,如果
len(tab)
为4,则生成长度为3的元组:或者将
repeat
硬编码到2
,或者不要尝试将变量数量的值解压为固定数量的变量。在相关问题 更多 >
编程相关推荐