創建一個所有元素都設置為 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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。