zoukankan      html  css  js  c++  java
  • pytorch 与 numpy 的数组广播机制

    numpy 的文档提到数组广播机制为:
    When operating on two arrays, NumPy compares their shapes element-wise. It starts with the trailing dimensions, and works its way forward. Two dimensions are compatible when
    they are equal, or

    1. one of them is 1
    2. If these conditions are not met, a ValueError: frames are not aligned exception is thrown, indicating that the arrays have incompatible shapes. The size of the resulting array is the maximum size along each dimension of the input arrays.

    翻译过来就是,从两个数组地末尾开始算起,若轴长相等或者其中一个地维度为1,则认为是广播兼容的,否则是不兼容地。广播兼容的数组会在缺失的维度和长度为1的维度上进行。

    例如:

    a.shape + b.shape c.shape
    (4, 1) + (1) --> (4, 1)
    (4, 1) + (3,) --> (4, 3)
    (2, 3, 4) + (1, 4) --> (2, 3, 4)
    (2, 3, 4) + (3, 1) --> (2, 3, 4)
    (2, 3, 4) + (2, 1, 1) --> (2, 3, 4)
    (2, 3, 4) + (3, ) X
    (4, 3) + (4,) X
    (4, 3) + (3,) --> (4, 3)
    (4, 3) + (3) --> (4, 3)

  • 相关阅读:
    解析·玄学 模拟退火
    NOIP2018 集训(三)
    NOIP2018 集训(二)
    NOIP2018 集训(一)
    动画制作-cartoon
    视频压缩-video cutter
    [里程碑]media pro sdk 1.0 finished
    图像去水印-image inpainting
    地平线检测horizon line detection
    二维数据缺失补全
  • 原文地址:https://www.cnblogs.com/zi-wang/p/9809096.html
Copyright © 2011-2022 走看看