Macaulay2 » Documentation
Packages » Macaulay2Doc » The Macaulay2 language » lists and sequences » applyTable
next | previous | forward | backward | up | index | toc

# applyTable -- apply a function to each element of a table

- Usage:
    `applyTable(T, f)`
- Inputs:
  - T, a list, a table (list of lists of the same length)
  - f, a function,
- Outputs:
  - A, a list, a table of the same shape as $T$, where the function $f$ has been applied elementwise

## Description

    i1 : t = table({1,3,5,7}, {0,1,2,4}, (i,j) -> i^j);

    i2 : netList t

         +-+-+--+----+
    o2 = |1|1|1 |1   |
         +-+-+--+----+
         |1|3|9 |81  |
         +-+-+--+----+
         |1|5|25|625 |
         +-+-+--+----+
         |1|7|49|2401|
         +-+-+--+----+

    i3 : netList applyTable(t, i -> 2*i)

         +-+--+--+----+
    o3 = |2|2 |2 |2   |
         +-+--+--+----+
         |2|6 |18|162 |
         +-+--+--+----+
         |2|10|50|1250|
         +-+--+--+----+
         |2|14|98|4802|
         +-+--+--+----+

    i4 : netList applyTable(t, isPrime)

         +-----+-----+-----+-----+
    o4 = |false|false|false|false|
         +-----+-----+-----+-----+
         |false|true |false|false|
         +-----+-----+-----+-----+
         |false|true |false|false|
         +-----+-----+-----+-----+
         |false|true |false|false|
         +-----+-----+-----+-----+

## See also

- isTable -- whether something is a list of lists of equal length
- subtable -- extract a subtable from a table
- table -- make a table from a binary function
- lists and sequences -- a detailed overview of lists and sequences in Macaulay2

## For the programmer

The object applyTable is a function closure.

The source of this document is in /build/macaulay2-88fgJW/macaulay2-1.25.11+ds/M2/Macaulay2/packages/Macaulay2Doc/functions/table-doc.m2:66:0.