Command: MapIndexed

NEST HelpDesk Command Index NEST Quick Reference

Name:
 MapIndexed - Apply a function  to each element of a list/string

Synopsis:
     [v1 ... vn] {f} MapIndexed -> [ f(v1,1) ... f(vn,n) ]

Parameters:
     [v1 ... vn] - list of n arbitrary objects or string.

     {f}         - function of two arguments and one return value.

Description:
     For each element of the input array, MapIndexed calls f with
     two arguments, the current index and the element. It replaces
     the element with the result of f.
     MapIndexed works similar to Map, however, in adition to the
     element its index within the array is also passed to the function.
     Note that the index starts with 1, according to Mathematica convention.
     This is unlike in forallindexed where in accordance with Postscript 
     array indices start with 0.
     The result of MapIndexed is a list with the same number of values as the
     argument list.
     If f does not return a value, MapIndexed fails.
     If f returns more than one value, the result of MapIndexed is
     undefined.

     Alternatives: Function MapIndexed_a for lists and  MapIndexed_s
     for strings (both undocumented) -> behaviour and synopsis are
     the same.

Examples:

   [1 2 3 4 5]  {add} MapIndexed -> [2 4 6 8 10]
   (abcd) {add} MapIndexed -> (bdfh)

Diagnostics:
 None

Bugs:

Author:
    Marc-Oliver Gewaltig

References:
 The Mathematica Book

SeeAlso:Map Table forall forallindexed
Source:
 /home/abuild/rpmbuild/BUILD/nest-2.4.1/lib/sli/mathematica.sli

NEST HelpDesk Command Index NEST Quick Reference

© 2000-2010 The NEST Initiative