当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python mxnet.symbol.sparse.sum用法及代码示例


用法:

mxnet.symbol.sparse.sum(data=None, axis=_Null, keepdims=_Null, exclude=_Null, name=None, attr=None, out=None, **kwargs)

参数

  • data(Symbol) - 输入
  • axis(Shape or None, optional, default=None) -沿其执行缩减的一个或多个轴。

    The default, axis=(), will compute over all elements into a scalar array with shape (1,).

    If axis is int, a reduction is performed on a particular axis.

    If axis is a tuple of ints, a reduction is performed on all the axes specified in the tuple.

    If exclude is true, reduction will be performed on the axes that are NOT in axis instead.

    Negative values means indexing from right to left.

  • keepdims(boolean, optional, default=0) - 如果设置为True,缩减的轴作为尺寸为一的维度留在结果中。
  • exclude(boolean, optional, default=0) - 是否对不在轴上的轴执行缩减。
  • name(string, optional.) - 结果符号的名称。

返回

结果符号。

返回类型

Symbol

计算给定轴上的数组元素的总和。

注意

sumsum_axis 是等价的。对于 csr 存储类型的 ndarray,支持沿轴 0 和轴 1 求和。将 keepdims 或 exclude 设置为 True 将导致回退到密集运算符。

例子:

data = [[[1, 2], [2, 3], [1, 3]],
        [[1, 4], [4, 3], [5, 2]],
        [[7, 1], [7, 2], [7, 3]]]

sum(data, axis=1)
[[  4.   8.]
 [ 10.   9.]
 [ 21.   6.]]

sum(data, axis=[1,2])
[ 12.  19.  27.]

data = [[1, 2, 0],
        [3, 0, 1],
        [4, 1, 0]]

csr = cast_storage(data, 'csr')

sum(csr, axis=0)
[ 8.  3.  1.]

sum(csr, axis=1)
[ 3.  4.  5.]

相关用法


注:本文由纯净天空筛选整理自apache.org大神的英文原创作品 mxnet.symbol.sparse.sum。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。