Last updated: 2023-03-16.
tf_quant_finance.math.pad.pad_tensors#
Pads the innermost dimension of Tensors to a common shape.
tf_quant_finance.math.pad.pad_tensors(
tensors, pad_values=None, dtype=None, name=None
)
Given a list of Tensors of the same dtype and with shapes
batch_shape_i + [n_i], pads the innermost dimension of each tensor to
batch_shape_i + [max(n_i)]. For each tensor t, the padding is done with
values t[..., -1].
Example. Pad with the terminal value#
x = [[1, 2, 3, 9], [2, 3, 5, 2]]
y = [4, 5, 8]
pad_tensors([x, y])
# Expected: [array([[1, 2, 3, 9], [2, 3, 5, 2]], array([4, 5, 8, 8])]
Example. Pad with user-supplied values#
x = [[1, 2, 3, 9], [2, 3, 5, 2]]
y = [4, 5, 8]
pad_tensors([x, y], pad_values=10)
# Expected: [array([[1, 2, 3, 9], [2, 3, 5, 2]], array([4, 5, 8, 10])]
Args:#
tensors: A list of tensors of the samedtypeand shapesbatch_shape_i + [n_i].pad_values: An optional scalarTensoror a list ofTensors of shapes broadcastable with the correspondingbatch_shape_iand the samedtypeaspad_values. Corresponds to the padded values used fortensors.dtype: The default dtype to use when converting values toTensors. Default value:Nonewhich means that default dtypes inferred by TensorFlow are used.name: Python string. The name to give to the ops created by this class. Default value:Nonewhich maps to the default namepad_tensors.
Returns:#
A list of Tensors of shape batch_shape_i + [max(n_i)].
Raises:#
ValueError: If input is not an instance of a list or a tuple.