Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

matrix add for filters

Add a matrix or scalar to a matrix.

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:

inputoutput
matrixmatrix

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]]