嗨,我是张量流的新手。我想在 tensorflow 中实现以下 python 代码。
import numpy as np
a = np.array([1,2,3,4,5,6,7,9,0])
print(a) ## [1 2 3 4 5 6 7 9 0]
print(a.shape) ## (9,)
b = a[:, np.newaxis] ### want to write this in tensorflow.
print(b.shape) ## (9,1)
原文由 Rahul 发布,翻译遵循 CC BY-SA 4.0 许可协议
我认为那将是
tf.expand_dims
-基本上,我们列出了要插入这个新轴的轴 ID,并且尾随轴/尺寸 _被推回_。
从链接的文档中,这里有几个扩展维度的例子 -