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 multiply for filters

Multiply two matrices using dot product.

Signature

> matrix multiply {flags} (other) ...rest

Flags

  • --swap, -s: Swap the left and right operands.
  • --multall, -a: Multiply the input matrix with all matrices given as arguments, chaining them left to right (e.g., $a | matrix multiply --multall $b $c multiplies all three together).

Parameters

  • other: The other matrix to multiply with.
  • ...rest: Additional matrices for chained multiplication (requires --multall).

Input/output types:

inputoutput
matrixmatrix

Examples

Multiply two 2x2 matrices

> [[1 2] [3 4]] | into matrix | matrix multiply ([[1 0] [0 1]] | into matrix) | matrix into-nu | to nuon
[[1.0, 2.0], [3.0, 4.0]]

Multiply a matrix by its inverse gives identity

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

Swap operands with --swap

> [[1 2] [3 4]] | into matrix | matrix multiply --swap ([[0 1] [1 0]] | into matrix) | matrix into-nu | to nuon
[[3.0, 4.0], [1.0, 2.0]]

Chain-multiply three matrices with --multall

> matrix identity 2 | matrix multiply --multall ([[2 0] [0 2]] | into matrix) ([[3 0] [0 3]] | into matrix) | matrix into-nu | to nuon
[[6.0, 0.0], [0.0, 6.0]]