Understanding Diag() In PyTorch And Tensors
diag() function in PyTorch: extracts or creates diagonals from 1D or 2D tensors with optional output argument. Examples and usage shown.
Buy Me a Coffee☕ *Memos: My post explains eye(). My post explains diagflat(). My post explains diag_embed(). My post explains diagonal(). diag() can create the 2D tensor of zero or more elements on the diagonal and zero or more 0, 0., 0.+0.j or False elsewhere from the 1D tensor of zero or more elements or can extract the 1D tensor of zero or more elements on the diagonal from the 2D tensor of zero or more elements as shown below: *Memos: diag() can be used with torch or a tensor. The 1st argument(input) with torch or using a tensor(Required-Type:tensor of int, float, complex or bool). *On...