Theano在张量中获得独特的价值

时间:2014-09-11 13:05:28

标签: python-2.7 numpy enthought theano

我有张量,我通过展平转换为矢量,现在我想删除此向量中的重复值。我怎样才能做到这一点?什么相当于theano中的numpy.unique()?

x1 = T.itensor3('x1')
y1 = T.flatten(x1)
#z1 = T.unique() How do I do this?

For e.g. my tensor may be : [1,1,2,3,3,4,4,5,1,3,4]
and I want : [1,2,3,4,5]

1 个答案:

答案 0 :(得分:3)

编辑:现在可以在Theano中使用:http://deeplearning.net/software/theano/library/tensor/extra_ops.html#theano.tensor.extra_ops.Unique

还在theano-user邮件列表上询问了这个问题。结论是,这是在Theano中没有包含的功能NumPy功能之一。因为他不需要毕业,所以可以迅速包裹。这是一个期望输出与输入相同的示例。

from theano.compile.ops import as_op


@as_op(itypes=[theano.tensor.imatrix],
       otypes=[theano.tensor.imatrix])
def numpy_unique(a):
    return numpy.unique(a)

有关as_op的更多文档,请访问:http://deeplearning.net/software/theano/tutorial/extending_theano.html#as-op-example