fn
block_diag
→Tensorblock_diag(tensors: Tensor = ())Construct a block-diagonal matrix from a sequence of blocks.
Each input is placed on the diagonal of a larger matrix, with zeros everywhere off-block. Scalars (0-D) become blocks and 1-D inputs become blocks before stacking.
Parameters
*tensorsTensorOne or more 0-, 1-, or 2-D tensors to place on the diagonal,
in order from top-left to bottom-right.
Returns
Tensor2-D block-diagonal matrix of shape
(sum(h_i), sum(w_i)) where h_i, w_i are the (promoted)
block heights and widths.
Notes
For blocks , the result is
Called with zero arguments, returns an empty (0, 0) matrix.
Examples
>>> import lucid
>>> A = lucid.tensor([[1., 2.], [3., 4.]])
>>> B = lucid.tensor([[5.]])
>>> lucid.block_diag(A, B)
Tensor([[1., 2., 0.],
[3., 4., 0.],
[0., 0., 5.]])