Met the same issue when using torch.stack() (see last answer):

  
    
    
    Optimizing diagonal stripe code 
  
  
    I need to get a diagonal stripe of the matrix. Say, I have a matrix of size KxN, where K and N are arbitrary sizes and K>N. Given a matrix: 
[[ 0  1  2]
 [ 3  4  5]
 [ 6  7  8]
 [ 9 10 11]]

From it I would need to extract a diagonal stripe, in this case, a matrix MxV size that is created by truncating the original one: 
[[ 0  x  x]
 [ 3  4  x]
 [ x  7  8]
 [ x  x  11]]

So the result matrix is: 
[[ 0  4  8]
 [ 3  7  11]]

Now, an additional problem that I face is that I have a tensor of, say, s…