Paddle icon indicating copy to clipboard operation
Paddle copied to clipboard

动态索引tensor中的一部分

Open zhoukunsheng opened this issue 7 years ago • 2 comments

构建网络时生成了序列的表示,其shape为(batch, seq_len, dim),同时生成了一个shape为(batch, seq_len) 的一个binary index,想要依据该binary index 从序列表示中gather 一部分tensor。请问是否可以实现呢?

zhoukunsheng avatar Jan 03 '19 01:01 zhoukunsheng

http://paddlepaddle.org/documentation/docs/zh/1.2/api_cn/layers_cn.html#gather 这是比较接近的一个op 你看能构造这样的输入吗

xuezhong avatar Jan 03 '19 03:01 xuezhong

https://github.com/PaddlePaddle/Paddle/blob/develop/python/paddle/fluid/tests/unittests/test_py_func_op.py#L97 这是个py_func的例子,你可以用Python实现op

xuezhong avatar Jan 03 '19 14:01 xuezhong