2015-03-13 88 views
0

是否有可能在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,T_z) 

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

#but how to make this work? 
print fun(a) 

如果列表中會發生什麼「一」有沒有兩個,而是數以千計的不同形狀的元素? 我唯一想到的就是將這些元素連接到一個大矩陣,然後繼續處理它。 沒有更好的解決方案嗎?

回答

0

也許你可以嘗試這樣的事:

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

# ln being your lists. 
my_func(l1, l2, l3...) 

會發生什麼事有,當你使用* ARGS在函數定義它意味着你可以通過任何數量的位置參數。

+0

thx,但是這也不被theano函數支持 – 2015-03-13 17:39:04