LinearAlgebra
Map
Map a procedure onto an expression, operating on Matrices and Vectors in-place
Map2
Calling Sequence
Parameters
Description
Examples
Map[filter](f, expr, arg2, ...)
Map2[filter](f, arg1, expr, arg2, ...)
filter
-
(optional) boolean-valued procedure; selects locations at which the function f is applied
f
procedure or name; procedure to apply to the operands of expr
expr
expression; expression being mapped
arg1
first argument to pass to f (Map2 only)
arg2, ...
(optional) further arguments to f
The Map(f, expr) calling sequence applies f to the operands of expr.
The ith operand of expr is replaced by the result of applying f to the ith operand. This is done for all the operands of expr.
If f takes more than one argument, they are included in the calling sequence as additional arguments arg2, arg3, ..., argn. They are passed as the second, third, ..., nth arguments to f.
The Map2(f, arg1, expr) calling sequence is similar to Map, except that for each operand of expr, arg1 is passed as the first argument to f, the operand of expr is passed as the second argument, and arg3, ..., argn are passed as the third, ..., nth arguments.
The Map and Map2 commands are identical to the map and map2 commands, respectively, except that if expr is a Matrix or Vector, then f is applied to the elements of that Matrix or Vector, and the application is done in-place.
Additionally, if any such application of f to an element of the Matrix or Vector fails to store (for example, in the case where the shape indicates that the corresponding location is not mutable), then that element is left unchanged. Thus, Map( ) and Map2( ) can be used to update the entries of an upper triangular Matrix. The diagonal entries of a unit triangular Matrix, for example, are not updated by Map( ) or Map2( ).
The optional filter parameter, passed as the index to the Map or Map2 command, restricts the application of f to the entries of expr for which the filter returns true. The filter is passed the index of the entry: for a Vector, it is passed one argument; for a Matrix, two arguments.
The filter parameter is ignored if expr is not a Matrix or Vector.
These functions are part of the LinearAlgebra package, and so they can be used in the form Map(..) or Map2(..) only after executing the command with(LinearAlgebra). However, they can always be accessed through the long form of the command by using LinearAlgebra[Map](..) or LinearAlgebra[Map2](..).
with⁡LinearAlgebra:
A≔Matrix⁡1,2,3,0,1,4,shape=triangularupper,unit
A≔123014
M≔Map⁡x↦x+1,A
M≔134015
evalb⁡addressof⁡A=addressof⁡M
true
B≔1,2,3|4,5,6
B≔142536
Map2i,j↦evalb⁡i=1⁡x,a↦a⋅x,3,B
3122536
Map⁡x↦x+1,g⁡3,A
g⁡4,234025
By default, these routines act only on the upper triangle of symmetric and skew-symmetric Matrices.
C≔Matrix⁡1,2,3,scan=triangularupper,shape=symmetric
C≔1223
Map⁡x↦x+1,C
2334
Map[proc(i,j) type(i+j,odd) end proc](x->x^2, C);
2994
See Also
map
Matrix
name
procedure
Vector
Download Help Document