Map a procedure onto an expression, operating on Matrices and Vectors in-place
Map[filter](f, expr, arg2, ...)
Map2[filter](f, arg1, expr, arg2, ...)
(optional) boolean-valued procedure; selects locations at which the function f is applied
procedure or name; procedure to apply to the operands of expr
expression; expression being mapped
first argument to pass to f (Map2 only)
(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](..).
A ≔ Matrix⁡1,2,3,0,1,4,shape=triangularupper,unit
M ≔ Map⁡x→x+1,A
B ≔ 1,2,3|4,5,6
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
Map[proc(i,j) type(i+j,odd) end proc](x->x^2, C);
Download Help Document