mygrad.concatenate#
- mygrad.concatenate((t1, t2, ...), axis=0, out=None, *, constant=None)[source]#
Join a sequence of tensors along an existing axis.
This docstring was adapted from that of numpy.concatenate [1]
- Parameters:
- tensorsSequence[ArrayLike]
The tensors must have the same shape, except in the dimension corresponding to axis (the first, by default).
- axisOptional[int]
The axis along which the tensors will be joined. If axis is
None, tensors are flattened before use. Default is 0.- outOptional[Union[ndarray, Tensor]]
If provided, the destination to place the result. The shape must be correct, matching that of what concatenate would have returned if no out argument were specified.
- constantOptional[bool]
If
True, this tensor is treated as a constant, and thus does not facilitate back propagation (i.e.constant.gradwill always returnNone).Defaults to
Falsefor float-type data. Defaults toTruefor integer-type data.Integer-type tensors must be constant.
- dtypeOptional[DTypeLikeReals]
If provided, the destination array will have this dtype. Cannot be provided together with
out.Requires numpy 1.20 or higher.
- Returns:
- resTensor
The concatenated tensor.
See also
stackStack a sequence of tensors along a new axis.
hstackStack tensors in sequence horizontally (column wise).
vstackStack tensors in sequence vertically (row wise).
dstackStack tensors in sequence depth wise (along third dimension).
References
[1]Retrieved from https://numpy.org/doc/stable/reference/generated/numpy.concatenate.html
Examples
>>> import mygrad as mg >>> a = mg.tensor([[1, 2], [3, 4]]) >>> b = mg.tensor([[5, 6]]) >>> mg.concatenate((a, b), axis=0) Tensor([[1, 2], [3, 4], [5, 6]]) >>> mg.concatenate((a, b.T), axis=1) Tensor([[1, 2, 5], [3, 4, 6]]) >>> mg.concatenate((a, b), axis=None) Tensor([1, 2, 3, 4, 5, 6])