Python 没有矩阵列表作为函数参数

Python 没有矩阵列表作为函数参数,python,list,function,matrix,theano,Python,List,Function,Matrix,Theano,是否可以在theano中定义一个函数,将矩阵列表(标量、向量)作为输入参数 这里有一个简单的例子: import numpy as np import theano as T import theano.tensor as TT a = [] a.append(np.zeros((2, 3))) a.append(np.ones((4, 3))) T_a = TT.matrices(len(a)) T_z = TT.concatenate(T_a) fun = T.function(T_a,

是否可以在theano中定义一个函数,将矩阵列表(标量、向量)作为输入参数

这里有一个简单的例子:

import numpy as np
import theano as T
import theano.tensor as TT

a = []
a.append(np.zeros((2, 3)))
a.append(np.ones((4, 3)))

T_a = TT.matrices(len(a))
T_z = TT.concatenate(T_a)
fun = T.function(T_a,T_z)

print fun(a[0],a[1])

#but how to make this work?
print fun(a)
如果列表“a”不是两个而是数千个具有不同形状的元素,会发生什么? 我唯一想到的是将这些元素连接到一个大矩阵,然后继续。
没有更好的解决方案吗?

也许您可以尝试以下方法:

def my_func(*args): 
    for list in args:
        # stuff here

# ln being your lists.
my_func(l1, l2, l3...)
在函数定义中使用*args意味着可以传递任意数量的位置参数