如何在TensorFlow中置入光明?

发布于 2025-02-14 01:40:34 字数 318 浏览 0 评论 0原文

我能够缩小张量的偏移:我可以在Pytorch中做到这一点!但是不在张量之类的地方!

A = torch.rand(1, 2,5)
A = A.permute(0,2,1) 
A.shape

Torch.Size([1,5,2])

TensorFlow(只是尝试一下,我不知道):

A = tf.random.normal(1, 2,5)
A = tf.keras.layers.Permute((0, 2, 1))

不工作

I am able to permute the dimmension of the tensor: I'm able to do this in pytorch! But not in tensorflow!

A = torch.rand(1, 2,5)
A = A.permute(0,2,1) 
A.shape

torch.Size([1, 5, 2])

Tensorflow (just a try,I don't know about this):

A = tf.random.normal(1, 2,5)
A = tf.keras.layers.Permute((0, 2, 1))

Not working

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

携君以终年 2025-02-21 01:40:34

使用TF.Transpose

import tensorflow as tf

A = tf.random.normal((1, 2, 5))

A_t = tf.transpose(A, perm=[0, 2, 1])

print(A.shape, A_t.shape)
# (1, 2, 5) (1, 5, 2)

Use tf.transpose:

import tensorflow as tf

A = tf.random.normal((1, 2, 5))

A_t = tf.transpose(A, perm=[0, 2, 1])

print(A.shape, A_t.shape)
# (1, 2, 5) (1, 5, 2)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文