创建一个用标量值填充的张量。
用法
tf.fill(
dims, value, name=None
)参数
-
dims一维非负数序列。表示输出tf.Tensor的形状。条目的类型应为:int32,int64。 -
value填充返回的tf.Tensor的值。 -
name可选字符串。输出的名称tf.Tensor。
返回
-
形状为
dims且 dtype 与value相同的tf.Tensor。
抛出
-
InvalidArgumentErrordims包含否定条目。 -
NotFoundErrordims包含非整数条目。
另见tf.ones、tf.zeros、tf.one_hot、tf.eye。
此操作创建一个形状为 dims 的张量并用 value 填充它。
例如:
tf.fill([2, 3], 9)
<tf.Tensor:shape=(2, 3), dtype=int32, numpy=
array([[9, 9, 9],
[9, 9, 9]], dtype=int32)>
tf.fill 在图形运行时评估并支持基于其他运行时的动态形状 tf.Tensors ,与 tf.constant(value, shape=dims) 不同,它将值嵌入为 Const 节点。
numpy 兼容性
类似于 np.full 。在 numpy 中,支持更多参数。将数字参数作为形状 (np.full(5, value)) 在 numpy 中用于指定一维形状结果是有效的,而 TensorFlow 不支持这种语法。
相关用法
- Python tf.fingerprint用法及代码示例
- Python tf.feature_column.crossed_column用法及代码示例
- Python tf.feature_column.sequence_categorical_column_with_identity用法及代码示例
- Python tf.function用法及代码示例
- Python tf.feature_column.categorical_column_with_vocabulary_list用法及代码示例
- Python tf.feature_column.categorical_column_with_hash_bucket用法及代码示例
- Python tf.feature_column.bucketized_column用法及代码示例
- Python tf.feature_column.categorical_column_with_identity用法及代码示例
- Python tf.feature_column.sequence_numeric_column用法及代码示例
- Python tf.feature_column.sequence_categorical_column_with_vocabulary_file用法及代码示例
- Python tf.feature_column.sequence_categorical_column_with_vocabulary_list用法及代码示例
- Python tf.feature_column.sequence_categorical_column_with_hash_bucket用法及代码示例
- Python tf.foldl用法及代码示例
- Python tf.feature_column.shared_embeddings用法及代码示例
- Python tf.feature_column.categorical_column_with_vocabulary_file用法及代码示例
- Python tf.feature_column.indicator_column用法及代码示例
- Python tf.feature_column.weighted_categorical_column用法及代码示例
- Python tf.foldr用法及代码示例
- Python tf.feature_column.numeric_column用法及代码示例
- Python tf.feature_column.embedding_column用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.fill。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
