matrix map

For filters.

Apply a closure to each element of a matrix and return a new matrix.

Command Type

built-in

Signature

> matrix map {flags} (closure)

Parameters

  • closure: The closure to apply to each element.

Input/output types:

input output
matrix matrix

Examples

Double each element in a matrix

> [[1 2] [3 4]] | into matrix | matrix map {|e| $e * 2} | matrix into-nu | to nuon
[[2.0, 4.0], [6.0, 8.0]]

Add 10 to each element of an identity matrix

> matrix identity 2 | matrix map {|e| $e + 10} | matrix into-nu | to nuon
[[11.0, 10.0], [10.0, 11.0]]

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