美文网首页
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小知识

    1. 将多个二维矩阵与一个二维矩阵相乘得到多个二维矩阵 In numpy, when i have a 3D te...

  • 开发小知识(一)

    开发小知识(一) 开发小知识(一)

  • 小知识

    夏天来了,格式冰冻的饮品也都上市了,什么冰激凌,炒冰,格式各样五花八门,我们要知道冰冻食物温度是0摄氏度,而我们人...

  • 小知识

    1字母默认大写的问题 以前了布局文件里定义一个text为字母的时候,很烦人的,它显示出来的默认就是大写,好烦人。今...

  • 小知识

  • 小知识

    气们不听话,一直雨加雪,她呼出一口热气,还有半小时锅就煮开了。 她去洗澡,水声隐隐想起一首歌,跟着哼唱。 她再回厨...

  • 小知识

    按住鼻翼两侧可以止住打喷嚏。 头发顺着发根到发梢的方向洗会柔顺很多。 鞋垫经常拿出来晾一晾可以...

  • 小知识

    #微协小分享# 今天微协君在桂花树上看到了一种果子,第一次见到它的微协君表示很神奇。原来这种果子叫桂花果[并不简单...

  • 小知识

    瓶装饮料扭不开怎么办,拍几下瓶底就可以轻松扭开,因为拍瓶底就会有小气泡冒出在整个瓶子里面会产生挤压里使瓶盖向上挤压...

  • 小知识

    1.元宵节:Lantern Festival 2.刺绣:Embroidery 3.重阳节:Double-Ninth...

网友评论

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

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