我有一个张量,通过展平将其转换为向量,现在我想删除该向量中的重复值。我怎样才能做到这一点? 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]
最佳答案
编辑:现在可以在 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
关于python-2.7 - Theano 获得张量中的唯一值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25788268/