MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / string_format

Function string_format

tensorflow/python/ops/string_ops.py:115–192  ·  view source on GitHub ↗

r"""Formats a string template using a list of tensors. Formats a string template using a list of tensors, abbreviating tensors by only printing the first and last `summarize` elements of each dimension (recursively). If formatting only one tensor into a template, the tensor does not have to

(template, inputs, placeholder="{}", summarize=3, name=None)

Source from the content-addressed store, hash-verified

113
114@tf_export("strings.format")
115def string_format(template, inputs, placeholder="{}", summarize=3, name=None):
116 r"""Formats a string template using a list of tensors.
117
118 Formats a string template using a list of tensors, abbreviating tensors by
119 only printing the first and last `summarize` elements of each dimension
120 (recursively). If formatting only one tensor into a template, the tensor does
121 not have to be wrapped in a list.
122
123 Example:
124 Formatting a single-tensor template:
125 ```python
126 sess = tf.compat.v1.Session()
127 with sess.as_default():
128 tensor = tf.range(10)
129 formatted = tf.strings.format("tensor: {}, suffix", tensor)
130 out = sess.run(formatted)
131 expected = "tensor: [0 1 2 ... 7 8 9], suffix"
132
133 assert(out.decode() == expected)
134 ```
135
136 Formatting a multi-tensor template:
137 ```python
138 sess = tf.compat.v1.Session()
139 with sess.as_default():
140 tensor_one = tf.reshape(tf.range(100), [10, 10])
141 tensor_two = tf.range(10)
142 formatted = tf.strings.format("first: {}, second: {}, suffix",
143 (tensor_one, tensor_two))
144
145 out = sess.run(formatted)
146 expected = ("first: [[0 1 2 ... 7 8 9]\n"
147 " [10 11 12 ... 17 18 19]\n"
148 " [20 21 22 ... 27 28 29]\n"
149 " ...\n"
150 " [70 71 72 ... 77 78 79]\n"
151 " [80 81 82 ... 87 88 89]\n"
152 " [90 91 92 ... 97 98 99]], second: [0 1 2 ... 7 8 9], suffix")
153
154 assert(out.decode() == expected)
155 ```
156
157 Args:
158 template: A string template to format tensor values into.
159 inputs: A list of `Tensor` objects, or a single Tensor.
160 The list of tensors to format into the template string. If a solitary
161 tensor is passed in, the input tensor will automatically be wrapped as a
162 list.
163 placeholder: An optional `string`. Defaults to `{}`.
164 At each placeholder occurring in the template, a subsequent tensor
165 will be inserted.
166 summarize: An optional `int`. Defaults to `3`.
167 When formatting the tensors, show the first and last `summarize`
168 entries of each tensor dimension (recursively). If set to -1, all
169 elements of the tensor will be shown.
170 name: A name for the operation (optional).
171
172 Returns:

Callers

nothing calls this directly

Calls 2

is_tensorMethod · 0.80
countMethod · 0.45

Tested by

no test coverage detected