matrix sum

For filters.

Sum all elements of a matrix, or sum along an axis.

Command Type

built-in

Signature

> matrix sum {flags}

Flags

  • --axis, -a {int}: The axis to sum along (0-based).

Input/output types:

input output
matrix float
matrix matrix

Examples

Sum all elements of a 2x2 matrix

> [[1 2] [3 4]] | into matrix | matrix sum
10.0

Sum along rows (axis 0)

> [[1 2] [3 4]] | into matrix | matrix sum --axis 0 | matrix into-nu | to nuon
[[4.0, 6.0]]

Sum along columns (axis 1)

> [[1 2] [3 4]] | into matrix | matrix sum --axis 1 | matrix into-nu | to nuon
[[3.0, 7.0]]

Ported from nushell/nushell.github.io. Copyright (c) 2021 Nushell Project. MIT License.