Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paddle list index/slice alternative method #47698

Closed
DrRyanHuang opened this issue Nov 6, 2022 · 3 comments
Closed

Paddle list index/slice alternative method #47698

DrRyanHuang opened this issue Nov 6, 2022 · 3 comments
Assignees
Labels
status/close 已关闭 type/feature-request 新需求申请

Comments

@DrRyanHuang
Copy link
Member

DrRyanHuang commented Nov 6, 2022

需求描述 Feature Description

Hi, thx for good jobs of Paddlepaddle!

I need an alternative method of paddle list slice/index. Could you please give me some advices?

numpy implementation:

import numpy as np
t_np = np.random.random([32, 7, 2, 40, 100])
t_np[1, :, :, [1, 2,-1], [1, 3,-1]].shape
(3, 7, 2)

torch implementation:

t_np = np.random.random([32, 7, 2, 40, 100])
t_tc = torch.Tensor(t_np)
t_tc[1, :, :, [1, 2,-1], [1, 3,-1]].shape
[7, 2, 3])

However

import paddle

t_pd = paddle.to_tensor(t_np)
t_pd[1, :, :, [1, 2,-1], [1, 3,-1]].shape

it raise:

(InvalidArgument) When index contains a list, its length is excepted to 1, but received 5

is there any simple alternative method for above implementation in paddle?

替代实现 Alternatives

No response

@paddle-bot
Copy link

paddle-bot bot commented Nov 6, 2022

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网API文档常见问题历史IssueAI社区来寻求解答。祝您生活愉快~

Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the APIFAQGithub Issue and AI community to get the answer.Have a nice day!

@huangjun12
Copy link
Contributor

import numpy as np
import paddle

t_np = np.random.random([32, 7, 2, 40, 100])
t_pd = paddle.to_tensor(t_np)

a = t_pd[1, :,:,:,:]

tmp_list = [a[:,:, 1, 1].unsqueeze(0), a[:,:, 2, 3].unsqueeze(0), a[:,:, -1, -1].unsqueeze(0)]

res = paddle.concat(tmp_list, axis=0)
print(res.shape)

with paddle develop, this code works well

@paddle-bot paddle-bot bot added status/following-up 跟进中 and removed status/new-issue 新建 labels Nov 7, 2022
@DrRyanHuang
Copy link
Member Author

@huangjun12 Thx!

@paddle-bot paddle-bot bot added status/close 已关闭 and removed status/following-up 跟进中 labels Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/close 已关闭 type/feature-request 新需求申请
Projects
None yet
Development

No branches or pull requests

2 participants