a = tf.reshape(b, [1, -1])

I don't know how many columes it can be, but I only want one row. Or

a = tf.reshape(b, [-1, 3])

I don't know how many rows it can be, but I  want 3 columes.

 

More examples for -1

>>> a = np.array([[1,2,3], [4,5,6]])
>>> np.reshape(a, (3,-1))       # the unspecified value is inferred to be 2
array([[1, 2],
       [3, 4],
       [5, 6]])
>>> a = np.arange(6).reshape((-1, 2))
>>> a
array([[0, 1],
       [2, 3],
       [4, 5]])

 


二维 trick

 mask = tf.reshape(mask, [tf.shape(mask)[0], -1])

 

GitHub 加速计划 / te / tensorflow
184.55 K
74.12 K
下载
一个面向所有人的开源机器学习框架
最近提交(Master分支:2 个月前 )
a49e66f2 PiperOrigin-RevId: 663726708 2 个月前
91dac11a This test overrides disabled_backends, dropping the default value in the process. PiperOrigin-RevId: 663711155 2 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐