创建一个所有元素都设置为 1 的张量。
用法
tf.compat.v1.ones_like(
tensor, dtype=None, name=None, optimize=True
)参数
-
tensor一个Tensor。 -
dtype返回的Tensor的类型。必须是float32,float64,int8,uint8,int16,uint16,int32,int64,complex64,complex128或bool。 -
name操作的名称(可选)。 -
optimize如果为真,尝试静态确定'tensor' 的形状并将其编码为常数。
返回
-
一个
Tensor,所有元素都设置为 1。
另见tf.ones。
给定单个张量 (tensor),此操作返回与 tensor 具有相同类型和形状的张量,所有元素都设置为 1。您可以选择为返回的张量指定新类型 (dtype)。
例如:
tensor = tf.constant([[1, 2, 3], [4, 5, 6]])
tf.ones_like(tensor) # [[1, 1, 1], [1, 1, 1]]
相关用法
- Python tf.compat.v1.distributions.Multinomial.stddev用法及代码示例
- Python tf.compat.v1.distribute.MirroredStrategy.experimental_distribute_dataset用法及代码示例
- Python tf.compat.v1.data.TFRecordDataset.interleave用法及代码示例
- Python tf.compat.v1.distributions.Bernoulli.cross_entropy用法及代码示例
- Python tf.compat.v1.Variable.eval用法及代码示例
- Python tf.compat.v1.train.FtrlOptimizer.compute_gradients用法及代码示例
- Python tf.compat.v1.layers.conv3d用法及代码示例
- Python tf.compat.v1.strings.length用法及代码示例
- Python tf.compat.v1.data.Dataset.snapshot用法及代码示例
- Python tf.compat.v1.data.experimental.SqlDataset.reduce用法及代码示例
- Python tf.compat.v1.feature_column.categorical_column_with_vocabulary_file用法及代码示例
- Python tf.compat.v1.data.TextLineDataset.from_tensors用法及代码示例
- Python tf.compat.v1.variable_scope用法及代码示例
- Python tf.compat.v1.data.experimental.SqlDataset.as_numpy_iterator用法及代码示例
- Python tf.compat.v1.distributions.Bernoulli.covariance用法及代码示例
- Python tf.compat.v1.placeholder用法及代码示例
- Python tf.compat.v1.layers.Conv3D用法及代码示例
- Python tf.compat.v1.train.get_or_create_global_step用法及代码示例
- Python tf.compat.v1.nn.static_rnn用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.compat.v1.ones_like。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
