inner(array1, array2, f, g, initf, initg)
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(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(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]]]
reduceAxis(anArray, f, axis, init)
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]
reduceDepth(anArray, f, depth, init)
Reduces the given array in the given depth.
depth and init are optional.
A.reduceDepth([[1, 2], [3, 4]], addf, 100)
// -> [3, 7]
concatDeep(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.concatDeep(1, [[1, 2], [3, 4]], [[5, 6, 7], [8, 9, 0]])
// -> [[1, 2, 5, 6, 7], [3, 4, 8, 9, 0]]
A.concatDeep(0.5, [[1, 2], [3, 4]], [[5, 6], [8, 9]])
// -> [[[1, 2], [5, 6]], [[3, 4], [8, 9]]]
A.concatDeep(-0.5, [1, 2, 3], [4, 5, 6])
// -> [[1, 2, 3], [4, 5, 6]]
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]]
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]]
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]]
isEmpty(anArray)
Returns true if the given array has no elements.
A.isEmpty([[], [[], []], []])
// -> true
A.isEmpty([[], [[], [2]], []])
// -> false
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(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(aVector)
Same as sortIndex(aVector, (x, y) => x > y ? -1 : x < y ? 1 : 0).
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]]
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]]
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(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(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]]
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(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]]
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]]