Paddle paddle2 tensor赋值报错

ve7v8dk2  于 2022-04-21  发布在  Java
关注(0)|答案(2)|浏览(274)

从官网nightly build安装的版本
碰到一个错误:

a = np.arange(0, 9).reshape(1, 9)
b = np.arange(1, 10).reshape(1, 9)
a[0] = b # 结果正常

a = paddle.to_tensor(a)
b = paddle.to_tensor(b)
a[0] = b  #错误

分析问题过程中发现paddle不区分0和[0]的shape,而numpy和torch区分:
numpy:

>>>np.array(0).shape
()
>>>np.array([0]).shape
(1,)

torch结果同上:

>>>torch.tensor(0).shape
torch.Size([])
>>>torch.tensor([0]).shape
torch.Size([1])

但是paddle结果如下:

>>>paddle.to_tensor(0).shape
[1]
>>>paddle.to_tensor([0]).shape
[1]

这样就会产生上面的问题,numpy下可以执行下面的代码,

a = np.arange(9).reshape(3,3)
b = np.arange(6).reshape(2,3)
c = np.arange(3).reshape(1,3)
idx1 = [1,2]
idx2 = [0]
a[idx1] = b
a[idx2] = c

但是paddle下执行a[idx2]就会报错了, 因为a[idx1] 和 a[idx2]返回的shape大小不一致,感觉很不易用。

mcvgt66p

mcvgt66p1#

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网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!

eivnm1vs

eivnm1vs2#

您好,感谢反馈问题,后续会进行评估修复。

相关问题