Creates a tensor with all elements set to 1.
Aliases:
tf.compat.v1.onestf.compat.v2.ones
tf.ones(
shape,
dtype=tf.dtypes.float32,
name=None
)
Used in the guide:
MigrateyourTensorFlow1codetoTensorFlow2``WritingcustomlayersandmodelswithKeras
Used in the tutorials:
AutomaticdifferentiationandgradienttapeBetterperformancewithtf.functionTransformermodelforlanguageunderstanding`` This operation returns a tensor of typedtypewithshapeshapeand all elements set to 1.
For example:
tf.ones([2, 3], tf.int32) # [[1, 1, 1], [1, 1, 1]]
Args:
shape: A list of integers, a tuple of integers, or a 1-DTensorof typeint32.dtype: The type of an element in the resultingTensor.name: Anamefor the operation (optional).
Returns:
A Tensor with all elements set to 1.