def concat(concat_dim, values, name="concat"): if not isinstance(values, (list, tuple)): values = [values] if len(values) == 1: # Degenerate case of one tensor. with ops.name_scope(name) as scope: ops.convert_to_tensor(concat_dim, name="concat_dim", dtype=dtypes.float32).get_shape( ).assert_is_compatible_with(tensor_shape.scalar()) return identity(values[0], name=scope) return gen_array_ops._concat(concat_dim=concat_dim, values=values, name=name)
def concat(concat_dim, values, name="concat"): """Concatenates tensors along one dimension. Concatenates the list of tensors `values` along dimension `concat_dim`. If `values[i].shape = [D0, D1, ... Dconcat_dim(i), ...Dn]`, the concatenated result has shape [D0, D1, ... Rconcat_dim, ...Dn] where Rconcat_dim = sum(Dconcat_dim(i)) That is, the data from the input tensors is joined along the `concat_dim` dimension. The number of dimensions of the input tensors must match, and all dimensions except `concat_dim` must be equal. For example: ```python t1 = [[1, 2, 3], [4, 5, 6]] t2 = [[7, 8, 9], [10, 11, 12]] tf.concat(0, [t1, t2]) ==> [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]] tf.concat(1, [t1, t2]) ==> [[1, 2, 3, 7, 8, 9], [4, 5, 6, 10, 11, 12]] # tensor t3 with shape [2, 3] # tensor t4 with shape [2, 3] tf.shape(tf.concat(0, [t3, t4])) ==> [4, 3] tf.shape(tf.concat(1, [t3, t4])) ==> [2, 6] ``` Args: concat_dim: 0-D `int32` `Tensor`. Dimension along which to concatenate. values: A list of `Tensor` objects or a single `Tensor`. name: A name for the operation (optional). Returns: A `Tensor` resulting from concatenation of the input tensors. """ if not isinstance(values, (list)): values = [values] # TODO(mrry): Change to return values? if len(values) == 1: # Degenerate case of one tensor. return identity(values[0], name=name) return gen_array_ops._concat(concat_dim=concat_dim, values=values, name=name)
def concat(concat_dim, values, name="concat"): """Concatenates tensors along one dimension. Concatenates the list of tensors `values` along dimension `concat_dim`. If `values[i].shape = [D0, D1, ... Dconcat_dim(i), ...Dn]`, the concatenated result has shape [D0, D1, ... Rconcat_dim, ...Dn] where Rconcat_dim = sum(Dconcat_dim(i)) That is, the data from the input tensors is joined along the `concat_dim` dimension. The number of dimensions of the input tensors must match, and all dimensions except `concat_dim` must be equal. For example: ```python t1 = [[1, 2, 3], [4, 5, 6]] t2 = [[7, 8, 9], [10, 11, 12]] tf.concat(0, [t1, t2]) ==> [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]] tf.concat(1, [t1, t2]) ==> [[1, 2, 3, 7, 8, 9], [4, 5, 6, 10, 11, 12]] # tensor t3 with shape [2, 3] # tensor t4 with shape [2, 3] tf.shape(tf.concat(0, [t3, t4])) ==> [4, 3] tf.shape(tf.concat(1, [t3, t4])) ==> [2, 6] ``` Args: concat_dim: 0-D `int32` `Tensor`. Dimension along which to concatenate. values: A list of `Tensor` objects or a single `Tensor`. name: A name for the operation (optional). Returns: A `Tensor` resulting from concatenation of the input tensors. """ if not isinstance(values, (list, tuple)): values = [values] # TODO(mrry): Change to return values? if len(values) == 1: # Degenerate case of one tensor. return identity(values[0], name=name) return gen_array_ops._concat(concat_dim=concat_dim, values=values, name=name)