inner

inner(array1, array2, f, g, initf, initg, depthf, depthg)

Calculates inner product of two arrays.
Arrays must be proper.
initf, initg are optional, then first value of array is used as initial value.

A.inner([[1, 2], [3, 4]], [[5, 6], [7, 8]], (accum, x) => accum + x, (accum, x) => accum * x))
// -> [[19, 22], [43, 50]]

outer

outer(array1, array2, f, depth)

Calculates outer product of two arrays.
depth is optional.

A.outer([1, 2, 3, 4, 5], [1, 2, 3, 4, 5], (x, y) => x * y)
// -> [[1, 2, 3, 4, 5],
//     [2, 4, 6, 8, 10],
//     [3, 6, 9, 12, 15],
//     [4, 8, 12, 16, 20],
//     [5, 10, 15, 20, 25]]

T

T(anArray)

Transposes the given array.
Array must be proper.

A.T([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [2, 3, 4]]])
// -> [[[1, 7], [4, 2]], [[2, 8], [5, 3]], [[3, 9], [6, 4]]]

transpose

transpose(anArray, ...axes)

Transposes axes as arguments axes.

A.transpose([[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [2, 3, 4]]], 1, 2, 0)
// -> [[[1, 7], [2, 8], [3, 9]], [[4, 2], [5, 3], [6, 4]]]

reduceAxis

reduceAxis(anArray, f, axis, init, pad)

Reduces the given array along the given axis.
Array must be proper.

A.reduceAxis([[1, 2], [3, 4]], (accum, x) => accum + x, 0)
// -> [4, 6]

reduceDeep

reduceDeep(anArray, f, depth, init)

Reduces the given array in the given depth.
depth and init are optional.

reduceAll

reduceAll(anArray, f, init)

Reduces all elements of the array.

A.reduceAll([[2, 3], [4, [5, 6], 7], 8, [9, 10]], (accum, x) => accum + x, 1)
// -> 55

reverseAxis

reverseAxis(array1, ...axes)

Reverses array along to argument axes.

A.reverseAxis([[[1, 2], [3, 4], [1, 2]], [[3, 4], [1, 2], [3, 4]]], 0, 2)
// -> [[[4, 3], [2, 1], [4, 3]], [[2, 1], [4, 3], [2, 1]]]

rotateAxis

rotateAxis(array1, rotate, axis)

Rotates array along to given axis.
Argument rotate must be scalar number or proper array of numbers.

A.rotateAxis([[1, 2], [3, 4], [5, 6]], [2, 1], 0)
// -> [[5, 4], [1, 6], [3, 2]]

shiftAxis

shiftAxis(array1, shift, axis, pad)

Shifts array along to given axis.
Argument rotate must be scalar number or proper array of numbers.

A.shiftAxis([[1, 2, 3], [4, 5, 6]], [2, 1], 1, 0)
// -> [[3, 0, 0], [5, 6, 0]]

reverseDeep

reverseDeep(anArray, depth)

Reverses array until the given depth.

A.reverseDeep([[1, 2], [3, 4]], 100)
// -> [[2, 1], [4, 3]]
A.reduceDeep([[1, 2], [3, 4]], addf, 100)
// -> [3, 7]

concatAxis

concatAxis(axis, ...arrays)

Concatenates the given arrays along the given axis.
If axis is decimal, concatenates the array between floor(axis) and ceil(axis) and cardinality increses.
If axis is negative number, concatenates first axis and cardinaity increses.

A.concatAxis(1, [[1, 2], [3, 4]], [[5, 6, 7], [8, 9, 0]])
// -> [[1, 2, 5, 6, 7], [3, 4, 8, 9, 0]]
A.concatAxis(0.5, [[1, 2], [3, 4]], [[5, 6], [8, 9]])
// -> [[[1, 2], [5, 6]], [[3, 4], [8, 9]]]
A.concatAxis(-0.5, [1, 2, 3], [4, 5, 6])
// -> [[1, 2, 3], [4, 5, 6]]

mapDeep

function mapDeep(f, depth, ...arrays)

Maps the given arrays in the given depth.
depth is not optional.
mapDeep broadcasts like NumPy, but mapDeep can not broadcast if cardinality of arrays are different.

A.mapDeep((accum, x) => accum + x, 100, [[1, 2], [3, 4]], [[5, 6], [7, 8]])
// -> [[6, 8], [10, 12]]
A.mapDeep((accum, x) => accum + x, 100, [[1, 2]], [[3], [4]])
// -> [[4, 5], [5, 6]]

map

map(f, ...arrays)

Equivalent to mapDeep(f, Number.MAX_SAFE_INTEGER, ...arrays).

 a + x, [[1, 2], [3, 4]], [[5, 6], [7, 8]])
// -> [[6, 8], [10, 12]]

mapScalar

mapScalar(anObject, f, scalar, depth)

Maps the each element of array and scalar.
depth is optional.

A.mapScalar([[1, 2], [3, 4]], (a, x) => a + x, 3)
// -> [[4, 5], [6, 7]]

replicateAxis

replicateAxis(array1, vector, axis, pad)

Replicates the array along to the axis.

A.replicateAxis([[1, 2, 3], [4, 5, 6]], [0, 2, 1], 1)
// -> [[2, 2, 3], [5, 5, 6]]

scanAxis

scanAxis(anArray, f, axis, init, depth)

Scans the array along to the given axis.

A.scanAxis([1, 2, 3], (accum, x) => accum + x, 0)
// -> [1, 3, 6]

scanAxisLast

scanAxisLast(anArray, f, init, depth)

Scans the array along to the last axis.

A.scanAxisLast([[1, 2, 3], [4, 5, 6], [7, 8, 9]], (accum, x) => accum - x, 0)
// -> [[2, 1, 0], [3, 3, 3], [7, 8, 9]]

decode

decode(array1, array2)

Decodes the array.

A.decode([2, 2, 2, 2], [1, 1, 1, 1])
// -> 15

encode

encode(array1, array2)

Encodes the array.

A.encode([1760, 3, 12], 75)
// -> [2, 0, 3]

equalsDeep

equalsDeep(...arrays)

Returns true if all arrays are equal.

A.equalsDeep([[1, 2], [3, 4]], [[1, 2], [3, 4]], [[1, 2], [3, 4]])
// -> true

reshape

reshape(shape, anArray)

Reshapes the given array specified the given shape vector.

A.reshape([2, 3], [[1, 2], [3, 4]])
// -> [[1, 2, 3], [4, 1, 2]]

vectorize

vectorize(anArray, depth)

Vectorize the array until the given depth.

A.vectorize([[1, 2], 3])
// -> [1, 2, 3]

isEmpty

isEmpty(anArray)

Returns true if the given array has no elements.

A.isEmpty([[], [[], []], []])
// -> true
A.isEmpty([[], [[], [2]], []])
// -> false

first

first(anArray)

Returns the first value of the array.

A.first([[[1], 2, [3, 4]]])
// -> 1

rank

rank(anArray)

Returns rank of the ginven array by shape vector.
If the array is not proper, returns null.

A.rank([[1, 2, 3], [4, 5, 6]])
// -> [2, 3]
A.rank([1, [2, 3]])
// -> null

sortIndex

sortIndex(aVector, cmp)

Sorts the given vector and returns vector consists of indices.
cmp is optional.

A.sortIndex([30, 50, 10, 90, 70])
// -> [2, 0, 1, 4, 3]

sortIndexDesc

sortIndexDesc(aVector)

Same as sortIndex(aVector, (x, y) => x > y ? -1 : x < y ? 1 : 0).

subarray

subarray(anArray, indices)

Returns subarray specified the given indices vector.
Each element of indices is null, integer, array of integer or function.
If the element is null, all elements are got in the dimension.
If the element is integer, element specified as integer is got and cardinality decreses.
If the element is array of integer, elements specified as integers are got.
If the element is function, elements fulfilled the condition are got.

A.subarray([[1, 2], [3, 4]], [null, 0])
// -> [1, 3]
A.subarray([[1, 2, 3], [4, 5, 6]], [(x, index) => index > 0, [1, 2]])
// -> [[5, 6]]

set

subarray(anArray, indices, rvalue, depth)

Set subarray of the array specified vector indices to the rvalue.
Each element of indices is null, integer, array of integer or function.
If the element is null, all elements are got in the dimension.
If the element is integer, element specified as integer is got and cardinality decreses.
If the element is array of integer, elements specified as integers are got.
If the element is function, elements fulfilled the condition are got.

A.set(x, [0, null], [9, 8, 7])
// -> [[1, 2, 3], [4, 5, 6]], [[9, 8, 7], [4, 5, 6]]

indexOfArray

indexOfArray(aVector, anArray)

Returns the array consists of indices of the given vector.

A.indexOfArray([1, 2, 3], [[0, 1], [2, 3]])
// -> [[-1, 0], [1, 2]]

lastIndexOfArray

lastIndexOfArray(aVector, anArray)

Returns the array consists of indices of the given vector from right to left.

A.lastIndexOfArray([1, 1, 0], [[0, 1], [2, 3]])
// -> [[2, 1], [-1, -1]]

generate

generate(g, size)

Generates the array which size is the given size and values are results of g().

A.generate(x => 1, 3)
// -> [1, 1, 1]

iterate

iterate(f, seed, size)

Generates the array which size is the given size and value are result of seed, f(seed), f(f(seed)), ....

A.iterate(x => x * 2, 1, 3)
// -> [1, 2, 4]

atArray

atArray(aVector, anArray)

Returns the array consists of values of the given vector.

A.atArray([1, 2, 3], [[0, 1], [2, -1]])
// -> [[1, 2], [3, 3]]

member

member(anArray, dest)

Returns the array if the element is in argument dest is 1, otherwise 0.

A.member([[2, 8], [7, -1]], [[2], [[7]]])
// -> [[1, 0], [1, 0]]

sliceDeep

sliceDeep(anArray, aVector)

Slices the given values by the given vector.

A.sliceDeep([[1, 2, 3], [4, 5, 6], [7, 8, 9]], [1, -2])
// -> [[5, 6], [8, 9]]

take

take(anArray, aVector)

Takes the given values by the given vector.

A.take([[1, 2, 3], [4, 5, 6], [7, 8, 9]], [-2, 2])
// -> [[4, 5], [7, 8]]

drop

Drops the given values by the given vector.

A.drop([[1, 2, 3], [4, 5, 6], [7, 8, 9]], [1, -1])
// -> [[4, 5], [7, 8]]

findArray

findArray(array, arraySearch, f)

Finds the arraySearch from the array.

A.findArray("SUNDAY".split(""), "DAY".split(""))
// -> [0, 0, 0, 1, 0, 0]