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

Change the dimensions of a matrix.

Signature

> matrix reshape {flags} (dimensions) ...rest

Flags

  • --flatten, -f: Flatten the matrix to a 1D vector

Parameters

  • dimensions: The new dimensions (e.g., 2 3 for a 2x3 matrix). Required unless --flatten is used.
  • ...rest: Additional dimensions for n-dimensional reshaping.

Input/output types:

inputoutput
matrixmatrix

Examples

Reshape a 1x6 matrix to 2x3

> [[1 2 3 4 5 6]] | into matrix | matrix reshape 2 3 | matrix into-nu | to nuon
[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]

Flatten a 2x2 matrix to 1D

> matrix identity 2 | matrix reshape --flatten | matrix into-nu | to nuon
[[1.0, 0.0, 0.0, 1.0]]