-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
使用 shape 为 (1, ) 的 Tensor 进行索引时会使结果少一根轴 #35891
Comments
您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网API文档、常见问题、历史Issue、AI社区来寻求解答。祝您生活愉快~ 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 API,FAQ,Github Issue and AI community to get the answer.Have a nice day! |
你好,复现了你说的情况,问题表现为,使用b = tensor[index]操作时,如果index的shape为1,则索引的结果b的维度比tensor的维度少一维。 这个并不算是bug,属于正常情况,假设tensor是二维的(h,w),index是一个整数(shape为[1]),此时结果b应该是tensor的某一行,shape为(w),如果index为一个list,shape为[c],结果b是tensor的某几行,shape为[c,w]。 也感谢指出,会反馈给相关同学,讨论是否修改这个逻辑。 |
感谢你的回答,不过这里我有点不同的想法
相对的,index 是整数的情况应当是 我认为,在使用 list 进行索引时,无论该 list 中有多少个元素,最终结果都不应该使 shape 发生改变,因为这会使得在完全相同(tensor 与 index 的阶数一致)的操作下获得了不同的结果,最终导致如我问题描述中所示,需要额外考虑 n == 1 的情况进行处理。 当然这只是我的个人见解,如有错误请尽管指正 |
@SigureMo 你好,咨询了负责同学,结论如下:
另外,感谢您的反馈,我们会持续优化,有任何建议都可以提出来 |
版本、环境信息:
问题描述
使用 shape 为 (1, ) 的 Tensor 对另一个 Tensor 进行索引时,结果会减少一根轴(见下面代码)
作为对比,我使用 numpy 和 pytorch 都进行了测试,结果是和预期一致的,即便索引(b)的 shape 为 (1, ),结果也不会少一根轴
我不太清楚这在 paddle 中是否是一个预期的效果,我并没有在文档中找到关于该特殊用例的详细说明,但至少它与 numpy 和 pytorch 的表现是不一致的
另外,为了防止数据在 n == 1 时丢失一根轴,目前我暂时使用的解决方案是
The text was updated successfully, but these errors were encountered: