如何检查两个张量的形状不兼容?

发布于 2025-01-27 23:10:19 字数 321 浏览 1 评论 0原文

是否有一种简单的方法来检查两个张量是否具有不兼容的形状(即,一个不可能的形状无法广播到另一个形状)?诸如

RuntimeError: The size of tensor a (?) must match the size of tensor b (?) at non-singleton dimension ?

我可以使用t1.size()[2]!= t2.size()[2]之类的错误(即,我知道何时以及如何发生)更复杂的场景),但是我如何习惯地说呢?

Is there a simple way to check if two tensors have incompatible shapes (i.e., one can not be broadcast to the shape of the other) before multiplying them? Errors such as

RuntimeError: The size of tensor a (?) must match the size of tensor b (?) at non-singleton dimension ?

I could use t1.size()[2] != t2.size()[2] in what I do (i.e., I know when and how that happens, but there could be more complicated scenarios), but how do I say it idiomatically?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文