0

How do I receive an array (like numpy ones) into a function? Let's say the array a = [[2],[3]] and the function f. Tuples works like this:

def f((a ,b)):
    print a * b

f((2,3))

But how is it with arrays?

def f(#here):
    print a*b

f([[2],[3]])
4

1 回答 1

1

函数参数中的元组解包已从 Python 3 中删除,因此我建议您停止使用它。

列表可以像元组一样被解包:

def f(arg):
    [[a], [b]] = arg

    return a * b

或者作为一个元组:

((x,), (y,)) = a

但我只会使用索引:

return arg[0][0] * arg[1][0]
于 2013-05-21T01:50:26.950 回答