r"""Creates a tensor filled with a scalar value. This operation creates a tensor of shape `dims` and fills it with `value`. For example: ``` # Output tensor has shape [2, 3]. fill([2, 3], 9) ==> [[9, 9, 9] [9, 9, 9]] ``` `tf.fill` differs from `tf.constant` i
(dims, value, name=None)
| 135 | |
| 136 | @tf_export("fill") |
| 137 | def fill(dims, value, name=None): |
| 138 | r"""Creates a tensor filled with a scalar value. |
| 139 | |
| 140 | This operation creates a tensor of shape `dims` and fills it with `value`. |
| 141 | |
| 142 | For example: |
| 143 | |
| 144 | ``` |
| 145 | # Output tensor has shape [2, 3]. |
| 146 | fill([2, 3], 9) ==> [[9, 9, 9] |
| 147 | [9, 9, 9]] |
| 148 | ``` |
| 149 | |
| 150 | `tf.fill` differs from `tf.constant` in a few ways: |
| 151 | |
| 152 | * `tf.fill` only supports scalar contents, whereas `tf.constant` supports |
| 153 | Tensor values. |
| 154 | * `tf.fill` creates an Op in the computation graph that constructs the |
| 155 | actual |
| 156 | Tensor value at runtime. This is in contrast to `tf.constant` which embeds |
| 157 | the entire Tensor into the graph with a `Const` node. |
| 158 | * Because `tf.fill` evaluates at graph runtime, it supports dynamic shapes |
| 159 | based on other runtime Tensors, unlike `tf.constant`. |
| 160 | |
| 161 | Args: |
| 162 | dims: A `Tensor`. Must be one of the following types: `int32`, `int64`. 1-D. |
| 163 | Represents the shape of the output tensor. |
| 164 | value: A `Tensor`. 0-D (scalar). Value to fill the returned tensor. |
| 165 | @compatibility(numpy) Equivalent to np.full @end_compatibility |
| 166 | name: A name for the operation (optional). |
| 167 | |
| 168 | Returns: |
| 169 | A `Tensor`. Has the same type as `value`. |
| 170 | """ |
| 171 | result = gen_array_ops.fill(dims, value, name=name) |
| 172 | tensor_util.maybe_set_static_shape(result, dims) |
| 173 | return result |
| 174 | |
| 175 | |
| 176 | @tf_export("identity") |