tf.ones_like
tf.ones_like(
tensor,
dtype=None,
name=None,
optimize=True
)
作用:Creates a tensor with all elements set to 1,及全部的值都设为1,保持 type
和shape
不变
- 例子:
tensor = tf.constant([[1, 2, 3], [4, 5, 6]])
tf.ones_like(tensor) # [[1, 1, 1], [1, 1, 1]]