the mapping function that takes an x
value from x_values
and a y
value from y_values
, and returns the mapped z_value.
the values to be used as the major axis (rows) of the resulting 2D array.
the values to be used as the minor axis (columns) of the resulting 2D array.
a 2D array with mapped values from x_values
and y_values
z
is a function of x
and y
defined by: z(x, y) = x + y
.
to create a 2d grid of z_values
using x_values = [1, 2, 3]
and y_values = [4, 5]
, we do the following:
import { assertEquals } from "jsr:@std/assert"
const
add = (x: number, y: number) => (x + y),
x_values = [1, 2, 3],
y_values = [4, 5],
z_values = meshMap(add, x_values, y_values)
assertEquals(z_values, [
[5, 6],
[6, 7],
[7, 8],
])
map two arrays to a "field" of 2D array through a mapping function.
given a mapping function
map_fn
, and two arraysx_values
andy_values
, this function generates a 2D array where each element is the result of applyingmap_fn
to the corresponding elements fromx_values
andy_values
.