如何在 TensorFlow 中更改变量的形状? [英] How can I change the shape of a variable in TensorFlow?

查看:54
本文介绍了如何在 TensorFlow 中更改变量的形状?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TensorFlow 教程说在创建时我们需要指定张量的形状.该形状自动成为张量的形状.它还说 TensorFlow 提供了重塑变量的高级机制.我怎样才能做到这一点?任何代码示例?

TensorFlow tutorial says that at creation time we need to specify the shape of tensors. That shape automatically becomes the shape of the tensor. It also says that TensorFlow provides advanced mechanisms to reshape variables. How can I do that? Any code example?

推荐答案

看一看 shapes-and-shaping 来自 TensorFlow 文档.它描述了可用的不同形状变换.

Take a look at shapes-and-shaping from TensorFlow documentation. It describes different shape transformations available.

最常见的函数可能是 tf.reshape,其中类似于它的 numpy 等价物.只要元素数量保持不变,它允许您指定所需的任何形状.文档中提供了一些示例.

The most common function is probably tf.reshape, which is similar to its numpy equivalent. It allows you to specify any shape that you want as long as the number of elements stays the same. There are some examples available in the documentation.

这篇关于如何在 TensorFlow 中更改变量的形状?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆