matrix add

For filters.

Add a matrix or scalar to a matrix.

Command Type

built-in

Signature

> matrix add {flags} (other)

Flags

  • --broadcast, -b: Enable broadcasting to allow compatible shapes

Parameters

  • other: The other matrix or scalar to add.

Input/output types:

input output
matrix matrix

Examples

Add a scalar to a matrix

> matrix zeros 2 2 | matrix add 5 | matrix into-nu | to nuon
[[5.0, 5.0], [5.0, 5.0]]

Add two matrices element-wise

> matrix identity 2 | matrix add (matrix identity 2) | matrix into-nu | to nuon
[[2.0, 0.0], [0.0, 2.0]]

Add with broadcasting a row vector

> matrix zeros 2 3 | matrix add --broadcast ([[1.0 2.0 3.0]] | into matrix) | matrix into-nu | to nuon
[[1.0, 2.0, 3.0], [1.0, 2.0, 3.0]]

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