Module pl.array2d

Operations on two-dimensional arrays.

Functions

column (a, key) extract a column from the 2D array.
extract_cols (t, cidx, a) extract the specified columns.
extract_rows (t, ridx, a) extract the specified rows.
forall (t, row_op, end_row_op, i1, j1, i2, j2, a) perform an operation for all values in a 2D array.
iter (a, indices, i1, j1, i2, j2) iterate over all elements in a 2D array, with optional indices.
map (f, a, arg) map a function over a 2D array
map2 (f, ad, bd, a, b, arg) map a function over two arrays.
product (f, t1, t2) cartesian product of two 1d arrays.
range (t, rstr) get a slice of a 2D array using spreadsheet range notation.
reduce2 (opc, opr, a) reduce a 2D array into a scalar, using two operations.
reduce_cols (f, a) reduce the columns using a function.
reduce_rows (f, a) reduce the rows using a function.
remove_col (t, j) remove a column from an array.
remove_row (t, i) remove a row from an array.
set (t, value, i1, j1, i2, j2) set a specified range of an array to a value.
slice (t, i1, j1, i2, j2) get a slice of a 2D array.
swap_cols (t, j1, j2, i1, i2) swap two columns of an array.
swap_rows (t, i1, i2) swap two rows of an array.
write (t, f, fmt, i1, j1, i2, j2) write a 2D array to a file.


Functions

column (a, key)
extract a column from the 2D array.

Parameters:

  • a: 2d array
  • key: an index or key

Return value:

    1d array
extract_cols (t, cidx, a)
extract the specified columns.

Parameters:

  • t:
  • cidx: a table of column indices
  • a: 2d array
extract_rows (t, ridx, a)
extract the specified rows.

Parameters:

  • t:
  • ridx: a table of row indices
  • a: 2d array
forall (t, row_op, end_row_op, i1, j1, i2, j2, a)
perform an operation for all values in a 2D array.

Parameters:

  • t:
  • row_op: function to call on each value
  • end_row_op: function to call at end of each row
  • i1: start row (default 1)
  • j1: end col (default M)
  • i2: end row (default N)
  • j2:
  • a: 2D array
iter (a, indices, i1, j1, i2, j2)
iterate over all elements in a 2D array, with optional indices.

Parameters:

  • a: 2D array
  • indices: with indices (default false)
  • i1: start row (default 1)
  • j1: end col (default M)
  • i2: end row (default N)
  • j2:

Return value:

    either value or i,j,value depending on indices
map (f, a, arg)
map a function over a 2D array

Parameters:

  • f: a function of at least one argument
  • a: 2d array
  • arg: an optional extra argument to be passed to the function.

Return value:

    2d array
map2 (f, ad, bd, a, b, arg)
map a function over two arrays. They can be both or either 2D arrays

Parameters:

  • f: function of at least two arguments
  • ad: order of first array
  • bd: order of second array
  • a: 1d or 2d array
  • b: 1d or 2d array
  • arg: optional extra argument to pass to function

Return value:

    2D array, unless both arrays are 1D
product (f, t1, t2)
cartesian product of two 1d arrays.

Parameters:

  • f: a function of 2 arguments
  • t1: a 1d table
  • t2: a 1d table

Return value:

    2d table
range (t, rstr)
get a slice of a 2D array using spreadsheet range notation.

Parameters:

  • t: a 2D array
  • rstr: range expression

Return value:

    a slice

See also:

reduce2 (opc, opr, a)
reduce a 2D array into a scalar, using two operations.

Parameters:

  • opc: operation to reduce the final result
  • opr: operation to reduce the rows
  • a: 2D array
reduce_cols (f, a)
reduce the columns using a function.

Parameters:

  • f: a binary function
  • a: 2d array

Return value:

    1d array

See also:

reduce_rows (f, a)
reduce the rows using a function.

Parameters:

  • f: a binary function
  • a: 2d array

Return value:

    1d array

See also:

remove_col (t, j)
remove a column from an array.

Parameters:

  • t: a 2d array
  • j: a column index
remove_row (t, i)
remove a row from an array.

Parameters:

  • t: a 2d array
  • i: a row index
set (t, value, i1, j1, i2, j2)
set a specified range of an array to a value.

Parameters:

  • t: a 2D array
  • value: the value
  • i1: start row (default 1)
  • j1: end col (default M)
  • i2: end row (default N)
  • j2:
slice (t, i1, j1, i2, j2)
get a slice of a 2D array. Note that if the specified range has a 1D result, the rank of the result will be 1.

Parameters:

  • t: a 2D array
  • i1: start row (default 1)
  • j1: end col (default M)
  • i2: end row (default N)
  • j2:

Return value:

    an array, 2D in general but 1D in special cases.
swap_cols (t, j1, j2, i1, i2)
swap two columns of an array.

Parameters:

  • t: a 2d array
  • j1:
  • j2:
  • i1: a column index
  • i2: a column index
swap_rows (t, i1, i2)
swap two rows of an array.

Parameters:

  • t: a 2d array
  • i1: a row index
  • i2: a row index
write (t, f, fmt, i1, j1, i2, j2)
write a 2D array to a file.

Parameters:

  • t: a 2D array
  • f: a file object (default stdout)
  • fmt: a format string (default is just to use tostring)
  • i1: start row (default 1)
  • j1: end col (default M)
  • i2: end row (default N)
  • j2:

Valid XHTML 1.0!