python-2.7 - Theano 获得张量中的唯一值

标签 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]

最佳答案

编辑:现在可以在 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/

相关文章:

python - 如何在DataFrame中找到相同的行——python

python - 在 Python 中提取特定值之间的子数组

python - Cython 导入错误 : No module named parallel

python - 使用 SQLAlchemy 思考特征

python - 从 Enthoughts 特征到 Python 原生对象的类型转换

python - 有没有更好的方法来按其属性之一拆分对象?

python - 我如何创建类似于 "set intersection"的东西,允许一个项目从单个集合中丢失 n/1 次或更多次?

python-2.7 - 如何在 wxpython 中向现有消息框添加一些文本?

python - scrapy 如何制作我自己的调度程序中间件

python - 由于在 Mac OS X 上 brew install gcc 后缺少 fortran 编译器,仍然无法安装 scipy