python - 如何在python中改变张量形状?
问题描述
假设我在 Tensorflow 中有一个 shape 的张量[3,4,4]
,它是未知的。我怎样才能改变它的形状[3,4,4,1]
?
我尝试使用 reshape 函数,但因为我不明确知道张量形状,所以不能直接使用它。
解决方案
Given t of shape [3,4,4]
, it can be reshape to [3,4,4, 1]
tf.reshape(t, [3,4,4, 1]) # by explicitly specifying the shape
tf.expandims(t, 3) # implicitly we expand the dimension 3 with size 1
推荐阅读
- javascript - Javascript 在 USB 流中编码“ENQ”ASCII 字符
- android - 反应本机键盘避免视图推动整个屏幕
- javascript - 构建后使用 BrowserRouter 时 React-Router 不起作用
- plot - seaborn 分布图
- javascript - 如何在同一个 html 页面上显示两个 p5js 草图?
- python - 安装 Django 3.2 时出现 Winerror8
- node.js - 节点js路由需要等待另一个请求的处理
- c# - 属性“ReferencePath”的加载失败。不能添加 ... 作为参考路径,因为它是相对的
- reactjs - ReactJS 通过 axios.post 从表单选择发送数据
- r - 使用循环重命名多个数据框的变量,从列表中引用数据框名称