Algosim documentation: entrywise

entrywise

Computes a vector or matrix from a homogeneous list of vectors or matrices by applying a number list function to each entry.

Syntax

Description

If L is a list of vectors or matrices of the same format and f a function that accepts a list of numbers and returns a number, then entrywise(L, f) returns the vector or matrix with the format of the elements of L whose entries are the images under f of the entrywise lists of numbers obtained from L.

In other words, if L is

L = '(A1, A2, ..., An),

where the elements Ak are either all vectors of dimension k or all matrices of size k×m, then entrywise(L, f) is, if the Ak’s are vectors, the vector A of dimension k with components

A[i] = f('(A1[i], A2[i], ..., An[i])),                 ∀i ∈ [1, k] ∩ ℤ

or, if the Ak’s are matrices, the matrix A with size k×m with entries

A[i, j] = f('(A1[i, j], A2[i, j], ..., An[i, j])),     ∀(i, j) ∈ [1, k]×[1, m] ∩ ℤ².

Examples

L ≔ compute(RandomIntMatrix(2, 1, 10), n, 1, 4)
⎛8  3⎞  ⎛9  6⎞  ⎛1  3⎞  ⎛7  4⎞
⎝6  6⎠  ⎝1  4⎠  ⎝6  8⎠  ⎝4  6⎠
entrywise(L, HarmonicMean)
⎛2.90071942446  3.69230769231⎞
⎝2.52631578947  5.64705882353⎠
inv(∑(L@inv)/4)
⎛−20.8980582524  −4.36893203883⎞
⎝ 6.04368932039   6.69902912621⎠