【问题标题】:theano list of matrices as function argumentTheano 矩阵列表作为函数参数
【发布时间】:2015-03-13 14:44:31
【问题描述】:

是否可以在 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”不是两个而是数千个不同形状的元素,会发生什么? 我想到的唯一一件事就是将这些元素连接到一个大矩阵中,然后继续它。 没有更好的解决方案吗?

【问题讨论】:

    标签: python list function matrix theano


    【解决方案1】:

    也许你可以试试这样的:

    def my_func(*args): 
        for list in args:
            # stuff here
    
    # ln being your lists.
    my_func(l1, l2, l3...)
    

    当您在函数定义中使用 *args 时,这意味着您可以传递任意数量的位置参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-08
      • 1970-01-01
      • 2017-03-31
      • 1970-01-01
      • 2014-12-08
      • 2013-09-10
      • 1970-01-01
      相关资源
      最近更新 更多