美文网首页
2018-07-20-pytroch小知识

2018-07-20-pytroch小知识

作者: 陆小杰_642e | 来源:发表于2018-07-20 15:48 被阅读0次

    1. 将多个二维矩阵与一个二维矩阵相乘得到多个二维矩阵

    • In numpy, when i have a 3D tensor X with shape [A, B, C] and a 2D tensor Y with shape [C, D], then np.dot(X, Y) gives a 3D tensor with shape [A, B, D].
      In PyTorch, i can do this as below.
    result = torch.mm(X.view(-1, C), Y)
    result = result.view(-1, B, D)
    

    [原问题链接](https://discuss.pytorch.org/t/how-can-i-compute-3d-tensor-2d-tensor-multiplication/639

    2. 批对角矩阵处理

    • Hi !
      I have a matrix n*m of n different vectors of dimensions m.
      I would like to get n matrices of size m*m with each matrix being a diagonal of a vector.

    I guess I could do:

    d = []
    for vec in mat:
       d.append(torch.diag(vec))
    torch.stack(d)
    

    [问题链接](https://discuss.pytorch.org/t/batch-of-diagonal-matrix/13560

    相关文章

      网友评论

          本文标题:2018-07-20-pytroch小知识

          本文链接:https://www.haomeiwen.com/subject/pgkqmftx.html