Options
All
  • Public
  • Public/Protected
  • All
Menu

Class NDArrayMath

Hierarchy

  • NDArrayMath

Index

Constructors

constructor

  • new NDArrayMath(backend: MathBackend, safeMode: boolean): NDArrayMath
  • Parameters

    • backend: MathBackend
    • safeMode: boolean

      In safe mode, you must use math operations inside a math.scope() which will automatically clean up intermediate NDArrays.

    Returns NDArrayMath

Properties

Protected backend

backend: MathBackend

Methods

abs

  • abs<T>(ndarray: T): T
  • Computes absolute value element-wise.

    Type parameters

    Parameters

    • ndarray: T

      The input NDArray.

    Returns T

acos

  • acos<T>(ndarray: T): T
  • Computes acos of the input NDArray element-wise, y = acos(x).

    Type parameters

    Parameters

    • ndarray: T

      The input NDArray.

    Returns T

add

  • Adds two NDArrays element-wise, A + B. Supports broadcasting. For a stricter version without broadcasting use math.addStrict().

    Type parameters

    • G: "float32" | "int32" | "bool"

    Parameters

    • a: NDArray<G>

      The first NDArray to add element-wise.

    • b: NDArray<G>

      The second NDArray to add element-wise.

    Returns NDArray<G>

addStrict

  • addStrict<D, T>(a: T, b: T): T
  • Adds two NDArrays element-wise, A + B. Inputs must be the same shape. For broadcasting support, use math.add() instead.

    Type parameters

    • D: "float32" | "int32" | "bool"

    • T: NDArray<D>

    Parameters

    • a: T

      The first NDArray to multiply element-wise.

    • b: T

      The second NDArray to multiply element-wise.

    Returns T

argMax

  • Returns the indices of the maximum values along an axis. The result has the same shape as input with the dimension along axis removed.

    Parameters

    • input: NDArray

      The input array.

    • Default value axis: number = null

      Optional. The dimension to reduce. By default it reduces across all axes and returns the flat index

    Returns NDArray<"int32">

argMaxEquals

  • Returns a 1 if the argMax of x1 and x2 are the same, otherwise 0.

    Parameters

    • x1: NDArray

      The first input NDArray.

    • x2: NDArray

      The second input NDArray.

    Returns Scalar<"bool">

argMin

  • Returns the indices of the minimum values along an axis. The result has the same shape as input with the dimension along axis removed.

    Parameters

    • input: NDArray

      The input array.

    • Default value axis: number = null

      Optional. The dimension to reduce. By default it reduces across all axes and returns the flat index.

    Returns NDArray<"int32">

arrayDividedByScalar

  • arrayDividedByScalar<T>(a: T, c: Scalar): T

arrayMinusScalar

  • arrayMinusScalar<T>(a: T, c: Scalar): T

asin

  • asin<T>(ndarray: T): T
  • Computes asin of the input NDArray element-wise, y = asin(x).

    Type parameters

    Parameters

    • ndarray: T

      The input NDArray.

    Returns T

atan

  • atan<T>(ndarray: T): T
  • Computes atan of the input NDArray element-wise, y = atan(x).

    Type parameters

    Parameters

    • ndarray: T

      The input NDArray.

    Returns T

avgPool

  • avgPool<T>(input: T, filterSize: [number, number] | number, strides: [number, number] | number, pad: "valid" | "same" | number): T
  • Computes the 2D average pooling of an image.

    Type parameters

    Parameters

    • input: T

      The input ndarray, of rank 4 or rank 3 of shape [batch, height, width, inChannels]. If rank 3, batch of 1 is assumed.

    • filterSize: [number, number] | number

      The filter size, a tuple [filterHeight, filterWidth].

    • strides: [number, number] | number

      The strides of the pooling: [strideHeight, strideWidth].

    • pad: "valid" | "same" | number

      A string from: 'same', 'valid'. The type of padding algorithm.

    Returns T

basicLSTMCell

  • Computes the next state and output of a BasicLSTMCell. This is only the forward mode. Derived from tf.contrib.rnn.BasicLSTMCell.

    Parameters

    • forgetBias: Scalar

      Forget bias for the cell.

    • lstmKernel: Array2D

      The weights for the cell.

    • lstmBias: Array1D

      The bias for the cell.

    • data: Array2D

      The input to the cell.

    • c: Array2D

      Previous cell state.

    • h: Array2D

      Previous cell output.

    Returns [Array2D, Array2D]

    Tuple [nextCellState, cellOutput]

batchNormalization2D

  • Batch normalization 2D. Mean, variance, scale, and offset can be of two shapes: 1) The same shape as the input: an Array2D. 2) In the common case, the depth dimension is the last dimension of x, so the values would be an Array1D of shape [depth].

    Parameters

    • x: Array2D

      The input NDArray.

    • mean: Array2D | Array1D

      A mean NDArray.

    • variance: Array2D | Array1D

      A variance NDArray.

    • Default value varianceEpsilon: number = 0.001

      A small float number to avoid dividing by 0.

    • Optional scale: Array2D | Array1D

      A scale NDArray.

    • Optional offset: Array2D | Array1D

      An offset NDArray.

    Returns Array2D

batchNormalization3D

  • Batch normalization 3D. Mean, variance, scale, and offset can be of two shapes: 1) The same shape as the input: an Array3D. 2) In the common case, the depth dimension is the last dimension of x, so the values would be an Array1D of shape [depth].

    Parameters

    • x: Array3D

      The input NDArray.

    • mean: Array3D | Array1D

      A mean NDArray.

    • variance: Array3D | Array1D

      A variance NDArray.

    • Default value varianceEpsilon: number = 0.001

      A small float number to avoid dividing by 0.

    • Optional scale: Array3D | Array1D

      A scale NDArray.

    • Optional offset: Array3D | Array1D

      An offset NDArray.

    Returns Array3D

ceil

  • ceil<T>(ndarray: T): T
  • Computes ceiling of input NDArray element-wise. y = ceil(x)

    Type parameters

    Parameters

    • ndarray: T

      The input NDArray.

    Returns T

clip

  • clip<T>(ndarray: T, min: number, max: number): T
  • Clips values element-wise.

    Type parameters

    Parameters

    • ndarray: T

      The input NDArray.

    • min: number

      Lower-bound of range to be clipped to.

    • max: number

      Upper-bound of range to be clipped to.

    Returns T

clone

  • clone<T>(ndarray: T): T
  • Clones an NDArray of any shape.

    Type parameters

    Parameters

    • ndarray: T

      The NDArray to clone.

    Returns T

concat1D

  • Concatenates two 1D arrays.

    For example, if: A: shape(3) = |r1, g1, b1| B: shape(2) = |r2, g2| C = concat1D(A, B) == |r1, g1, b1, r2, g2|

    Parameters

    Returns Array1D

    The concatenated array.

concat2D

  • Concatenates two 2D arrays along a given axis.

    For example, if: A: shape(2, 3) = | r1, g1, b1 | | r2, g2, b2 |

    B: shape(2, 3) = | r3, g3, b3 | | r4, g4, b4 |

    C = concat2D(A, B, axis)

    if axis = 0: C: shape(4, 3) = | r1, g1, b1 | | r2, g2, b2 | | r3, g3, b3 | | r4, g4, b4 |

    if axis = 1: C = shape(2, 6) = | r1, g1, b1, r3, g3, b3 | | r2, g2, b2, r4, g4, b4 |

    Parameters

    • a: Array2D

      The first array.

    • b: Array2D

      The second array.

    • axis: number

      The axis to concatenate along.

    Returns Array2D

    The concatenated array.

concat3D

  • Concatenates two 3D ndarrays along a given axis.

    For example, if: A: shape(2, 1, 3) = | r1, g1, b1 | | r2, g2, b2 |

    B: shape(2, 1, 3) = | r3, g3, b3 | | r4, g4, b4 |

    C = concat3D(A, B, axis)

    if axis = 0: C: shape(4, 1, 3) = | r1, g1, b1 | | r2, g2, b2 | | r3, g3, b3 | | r4, g4, b4 |

    if axis = 1: C: shape(2, 2, 3) = | r1, g1, b1, r3, g3, b3 | | r2, g2, b2, r4, g4, b4 |

    if axis = 2: C = shape(2, 1, 6) = | r1, g1, b1, r3, g3, b3 | | r2, g2, b2, r4, g4, b4 |

    Parameters

    • ndarray1: Array3D

      The first array to concat.

    • ndarray2: Array3D

      The second array to conat.

    • axis: number

      The axis to concate along.

    Returns Array3D

    The concatenated array.

concat4D

  • Concatenates two 4D ndarrays along a given axis. See math.concat2D() for documentation.

    Parameters

    • ndarray1: Array4D

      The first array to concat.

    • ndarray2: Array4D

      The second array to conat.

    • axis: number

      The axis to concate along.

    Returns Array4D

    The concatenated array.

conv2d

  • conv2d<T>(input: T, filter: Array4D, bias: Array1D | null, strides: [number, number] | number, pad: "valid" | "same" | number): T
  • Computes a 2D convolution over the input x.

    Type parameters

    Parameters

    • input: T

      The input ndarray, of rank 4 or rank 3, of shape [batch, height, width, inChannels]. If rank 3, batch of 1 is assumed.

    • filter: Array4D

      The filter, rank 4, of shape [filterHeight, filterWidth, inDepth, outDepth].

    • bias: Array1D | null

      Optional bias, rank 1 of shape [outDepth].

    • strides: [number, number] | number

      The strides of the convolution: [strideHeight, strideWidth].

    • pad: "valid" | "same" | number

      A string from: 'same', 'valid'. The type of padding algorithm.

    Returns T

conv2dDerBias

  • Computes the derivative of the bias of a 2D convolution.

    Parameters

    • dy: Array3D | Array4D

      The gradient for the output of this op, of rank 4 or rank 3 of shape [batch, height, width, outDepth]. If rank 3, batch of 1 is assumed.

    Returns Array1D

conv2dDerFilter

  • conv2dDerFilter<T>(input: T, dy: T, filterShape: [number, number, number, number], strides: [number, number] | number, pad: "valid" | "same" | number): Array4D
  • Computes the derivative of the filter of a 2D convolution.

    Type parameters

    Parameters

    • input: T

      The input ndarray, of rank 4 or rank 3 of shape [batch, height, width, inChannels]. If rank 3, batch of 1 is assumed.

    • dy: T

      The dy image, of rank 4 or rank 3, of shape [batch, height, width, outDepth]. If rank 3, batch of 1 is assumed.

    • filterShape: [number, number, number, number]

      The shape of the filter, length 4, [filterHeight, filterWidth, inDepth, outDepth].

    • strides: [number, number] | number

      The strides of the convolution: [strideHeight, strideWidth].

    • pad: "valid" | "same" | number

      A string from: 'same', 'valid'. The type of padding algorithm used in the forward prop of the op.

    Returns Array4D

conv2dDerInput

  • conv2dDerInput<T>(inShape: [number, number, number, number] | [number, number, number], dy: T, filter: Array4D, strides: [number, number] | number, pad: "valid" | "same" | number): T
  • Computes the derivative of the input of a 2D convolution.

    Type parameters

    Parameters

    • inShape: [number, number, number, number] | [number, number, number]

      The shape of the input: [batch, height, width, inDepth]. If length of 3, batch of 1 is assumed.

    • dy: T

      The derivative of the output, of rank 4 or rank 3 of shape [batch, outHeight, outWidth, outDepth]. If rank 3, batch of 1 is assumed.

    • filter: Array4D

      The filter, rank 4, of shape [filterHeight, filterWidth, inDepth, outDepth].

    • strides: [number, number] | number

      The strides of the convolution: [strideHeight, strideWidth].

    • pad: "valid" | "same" | number

      A string from: 'same', 'valid'. The type of padding algorithm used in the forward prop of the op.

    Returns T

conv2dTranspose

  • conv2dTranspose<T>(x: T, filter: Array4D, outputShape: [number, number, number, number] | [number, number, number], strides: [number, number] | number, pad: "valid" | "same" | number): T
  • Computes the transposed 2D convolution of an image, also known as a deconvolution.

    Type parameters

    Parameters

    • x: T

      The input image, of rank 4 or rank 3, of shape [batch, height, width, inDepth]. If rank 3, batch of 1 is assumed.

    • filter: Array4D

      The filter, rank 4, of shape [filterHeight, filterWidth, outDepth, inDepth]. inDepth must match inDepth in x.

    • outputShape: [number, number, number, number] | [number, number, number]

      Output shape, of rank 4 or rank 3: [batch, height, width, outDepth]. If rank 3, batch of 1 is assumed.

    • strides: [number, number] | number

      The strides of the original convolution: [strideHeight, strideWidth].

    • pad: "valid" | "same" | number

      A string from: 'same', 'valid'. The type of padding algorithm used in the non-transpose version of the op.

    Returns T

copy2D

  • copy2D(source: Array2D, sourceBegin: [number, number], sourceSize: [number, number], dest: Array2D, destBegin: [number, number], destSize: [number, number]): void
  • Copies a window from the source matrix starting at sourceBegin and is of size sourceSize to a window in the dest matrix starting at destBegin and is of size destSize/

    Parameters

    • source: Array2D

      The source matrix to copy from.

    • sourceBegin: [number, number]

      The coordinates to start the copy from.

    • sourceSize: [number, number]

      The size of the copy window.

    • dest: Array2D

      The destination matrix to copy to.

    • destBegin: [number, number]

      The coordinates in dest to copy to.

    • destSize: [number, number]

      The size of the destination window.

    Returns void

cos

  • cos<T>(ndarray: T): T
  • Computes cos of the input NDArray element-wise, y = cos(x).

    Type parameters

    Parameters

    • ndarray: T

      The input NDArray.

    Returns T

cosh

  • cosh<T>(ndarray: T): T
  • Computes hyperbolic cos of the input NDArray element-wise, y = cosh(x).

    Type parameters

    Parameters

    • ndarray: T

      The input NDArray.

    Returns T

depthwiseConv2D

  • depthwiseConv2D<T>(input: T, filter: Array4D, strides: [number, number] | number, pad: "valid" | "same" | number, rates?: [number, number] | number): T
  • Depthwise 2D convolution.

    Given a 4D input array and a filter array of shape [filterHeight, filterWidth, inChannels, channelMultiplier] containing inChannels convolutional filters of depth 1, this op applies a different filter to each input channel (expanding from 1 channel to channelMultiplier channels for each), then concatenates the results together. The output has inChannels * channelMultiplier channels.

    See https://www.tensorflow.org/api_docs/python/tf/nn/depthwise_conv2d for more details.

    Type parameters

    Parameters

    • input: T

      The input ndarray, of rank 4 or rank 3, of shape [batch, height, width, inChannels]. If rank 3, batch of 1 is assumed.

    • filter: Array4D

      The filter ndarray, rank 4, of shape [filterHeight, filterWidth, inChannels, channelMultiplier].

    • strides: [number, number] | number

      The strides of the convolution: [strideHeight, strideWidth]. If strides is a single number, then strideHeight == strideWidth.

    • pad: "valid" | "same" | number

      A string from: 'same', 'valid'. The type of padding algorithm.

    • Default value rates: [number, number] | number = [1, 1]

      The dilation rates: [rateHeight, rateWidth] in which we sample input values across the height and width dimensions in atrous convolution. Defaults to [1, 1]. If rate is a single number, then rateHeight == rateWidth. If it is greater than 1, then all values of strides must be 1.

    Returns T

dispose

  • dispose(): void
  • Disposes the math object and any resources used by it.

    Returns void

divide

  • Divides two NDArrays element-wise, A / B. Supports broadcasting. For a stricter version without broadcasting use math.divideStrict().

    Parameters

    • a: NDArray

      The first NDArray to divide element-wise.

    • b: NDArray

      The second NDArray to divide element-wise.

    Returns NDArray<"float32">

divideStrict

  • divideStrict<T>(a: T, b: T): T
  • Divides two NDArrays element-wise, A / B. Inputs must be the same shape. For broadcasting support, use math.divide() instead.

    Type parameters

    Parameters

    • a: T

      The first NDArray to multiply element-wise.

    • b: T

      The second NDArray to multiply element-wise.

    Returns T

dotProduct

  • Computes the dot product of two vectors, v1 * v2.

    Parameters

    • v1: Array1D

      The first vector in the dot product operation.

    • v2: Array1D

      The second vector in the dot product operation.

    Returns Scalar

elementWiseMul

  • elementWiseMul<T>(a: T, b: T): T
  • deprecated

    Use math.multiplyStrict() instead.

    Type parameters

    Parameters

    • a: T
    • b: T

    Returns T

elementWiseMulBroadcast

elu

  • elu<T>(ndarray: T): T
  • Computes exponential linear element-wise

    Type parameters

    Parameters

    • ndarray: T

      the input NDArray

    Returns T

enableDebugMode

  • enableDebugMode(): void
  • In debug mode, the output of every math call will be downloaded to the CPU and checked for NaNs. This significantly impacts performance.

    Returns void

endScope

  • End a scope. Use this with startScope() to achieve the same functionality as scope() without the need for a function closure.

    Parameters

    Returns void

equal

  • Returns the truth value of (x == y) element-wise. Supports broadcasting. For a stricter version without broadcasting use math.equalStrict().

    Parameters

    Returns NDArray<"bool">

equalStrict

  • equalStrict<D, T>(x: T, y: T): NDArray<"bool">

exp

  • exp<T>(ndarray: T): T
  • Computes exponential of the input NDArray element-wise. y = e ^ x

    Type parameters

    Parameters

    • ndarray: T

      The input NDArray.

    Returns T

floor

  • floor<T>(ndarray: T): T
  • Computes floor of input NDArray element-wise. y = floor(x)

    Type parameters

    Parameters

    • ndarray: T

      The input NDArray.

    Returns T

keep

  • keep<T>(result: T): T
  • Keeps an NDArray in the current scope from being disposed automatically.

    Type parameters

    Parameters

    • result: T

      The NDArray to keep from being disposed.

    Returns T

leakyRelu

  • leakyRelu<T>(ndarray: T, alpha?: number): T
  • Computes leaky rectified linear element-wise

    Type parameters

    Parameters

    • ndarray: T

      the input NDArray

    • Default value alpha: number = 0.2

      scaleing factor for negative values, defaults to 0.2

    Returns T

log

  • log<T>(ndarray: T): T
  • Computes natural logarithm of the input NDArray element-wise. y = ln(x)

    Type parameters

    Parameters

    • ndarray: T

      The input NDArray.

    Returns T

logSumExp

  • logSumExp(input: NDArray, axis?: number | number[], keepDims?: boolean): NDArray
  • Computes the log(sum(exp(elements across the reduction dimensions)).

    Reduces the input along the dimensions given in axis. Unless keepDims is true, the rank of the array is reduced by 1 for each entry in axis. If keepDims is true, the reduced dimensions are retained with length 1. If axis has no entries, all dimensions are reduced, and an array with a single element is returned.

    Parameters

    • input: NDArray

      The input NDArray.

    • Default value axis: number | number[] = null

      Optional. The dimension(s) to reduce. If null (the default), reduces all dimensions.

    • Default value keepDims: boolean = false

      Optional. If true, retains reduced dimensions with length of 1. Defaults to false.

    Returns NDArray

matMul

  • matMul(a: Array2D, b: Array2D, aOrientation?: MatrixOrientation.REGULAR | MatrixOrientation.TRANSPOSED, bOrientation?: MatrixOrientation.REGULAR | MatrixOrientation.TRANSPOSED): Array2D
  • Computes the dot product of two matrices, A * B. These must be matrices, use matrixTimesVector and vectorTimesMatrix, dotProduct, and outerProduct in other cases.

    Parameters

    • a: Array2D

      First matrix in dot product operation.

    • b: Array2D

      Second matrix in dot product operation.

    • Default value aOrientation: MatrixOrientation.REGULAR | MatrixOrientation.TRANSPOSED = MatrixOrientation.REGULAR

      The MatrixOrientation of A. If using TRANSPOSED, will compute A^T * B.

    • Default value bOrientation: MatrixOrientation.REGULAR | MatrixOrientation.TRANSPOSED = MatrixOrientation.REGULAR

      The MatrixOrientation of B. If using TRANSPOSED, will compute A * B^T.

    Returns Array2D

matrixTimesVector

  • Computes the dot product of a matrix and vector, A * v.

    Parameters

    • matrix: Array2D

      The matrix in dot product operation.

    • v: Array1D

      The vector in dot product operation.

    Returns Array1D

max

  • max<G>(input: NDArray<G>, axis?: number | number[], keepDims?: boolean): NDArray<G>
  • Computes the maximum of elements across dimensions of an array.

    Reduces the input along the dimensions given in axes. Unless keepDims is true, the rank of the array is reduced by 1 for each entry in axes. If keepDims is true, the reduced dimensions are retained with length 1. If axes has no entries, all dimensions are reduced, and an array with a single element is returned.

    Type parameters

    • G: "float32" | "int32" | "bool"

    Parameters

    • input: NDArray<G>

      The input array.

    • Default value axis: number | number[] = null

      Optional. The dimension(s) to reduce. By default it reduces all dimensions.

    • Default value keepDims: boolean = false

      Optional. If true, retains reduced dimensions with size 1.

    Returns NDArray<G>

maxPool

  • maxPool<T>(input: T, filterSize: [number, number] | number, strides: [number, number] | number, pad: "valid" | "same" | number): T
  • Computes the 2D max pooling of an image.

    Type parameters

    Parameters

    • input: T

      The input ndarray, of rank 4 or rank 3 of shape [batch, height, width, inChannels]. If rank 3, batch of 1 is assumed.

    • filterSize: [number, number] | number

      The filter size, a tuple [filterHeight, filterWidth].

    • strides: [number, number] | number

      The strides of the pooling: [strideHeight, strideWidth].

    • pad: "valid" | "same" | number

      A string from: 'same', 'valid'. The type of padding algorithm.

    Returns T

maxPoolBackprop

  • maxPoolBackprop<T>(dy: T, input: T, filterSize: [number, number] | number, strides: [number, number] | number, pad: "valid" | "same" | number): T
  • Computes the backprop of a max pool.

    Type parameters

    Parameters

    • dy: T

      The dy error, of rank 4 or rank 3 of shape [batchSize, height, width, channels]. If rank 3, batch of 1 is assumed.

    • input: T

      The input image, of rank 4 or rank 3 of shape [batchSize, height, width, channels]. If rank 3, batch of 1 is assumed.

    • filterSize: [number, number] | number

      The filter size, a tuple [filterHeight, filterWidth].

    • strides: [number, number] | number

      The strides of the pooling: [strideHeight, strideWidth].

    • pad: "valid" | "same" | number

      A string from: 'same', 'valid'. The type of padding algorithm used in the forward prop of the op.

    Returns T

mean

  • mean(x: NDArray, axis?: number | number[], keepDims?: boolean): NDArray<"float32">
  • Computes the mean of elements across dimensions of an array.

    Reduces x along the dimensions given in axis. Unless keepDims is true, the rank of the array is reduced by 1 for each entry in axis. If keepDims is true, the reduced dimensions are retained with length 1. If axis has no entries, all dimensions are reduced, and an array with a single element is returned.

    Parameters

    • x: NDArray

      The input array.

    • Default value axis: number | number[] = null

      Optional. The dimension(s) to reduce. By default it reduces all dimensions.

    • Default value keepDims: boolean = false

      Optional. If true, retains reduced dimensions with size 1.

    Returns NDArray<"float32">

min

  • min<G>(input: NDArray<G>, axis?: number | number[], keepDims?: boolean): NDArray<G>
  • Computes the minimum value from the input.

    Reduces the input along the dimensions given in axes. Unless keepDims is true, the rank of the array is reduced by 1 for each entry in axes. If keepDims is true, the reduced dimensions are retained with length 1. If axes has no entries, all dimensions are reduced, and an array with a single element is returned.

    Type parameters

    • G: "float32" | "int32" | "bool"

    Parameters

    • input: NDArray<G>

      The input NDArray.

    • Default value axis: number | number[] = null

      Optional. The dimension(s) to reduce. By default it reduces all dimensions.

    • Default value keepDims: boolean = false

      Optional. If true, retains reduced dimensions with size 1.

    Returns NDArray<G>

minPool

  • minPool<T>(input: T, filterSize: [number, number] | number, strides: [number, number] | number, pad: "valid" | "same" | number): T
  • Computes the 2D min pooling of an image.

    Type parameters

    Parameters

    • input: T

      The input ndarray, of rank 4 or rank 3 of shape [batch, height, width, inChannels]. If rank 3, batch of 1 is assumed.

    • filterSize: [number, number] | number

      The filter size, a tuple [filterHeight, filterWidth].

    • strides: [number, number] | number

      The strides of the pooling: [strideHeight, strideWidth].

    • pad: "valid" | "same" | number

      A string from: 'same', 'valid'. The type of padding algorithm.

    Returns T

moments

  • moments(x: NDArray, axis?: number | number[], keepDims?: boolean): object
  • Calculates the mean and variance of x. The mean and variance are calculated by aggregating the contents of x across axes. If x is 1-D and axes = [0] this is just the mean and variance of a vector.

    Parameters

    • x: NDArray

      The input array.

    • Default value axis: number | number[] = null

      Optional. The dimension(s) along with to compute mean and variance. By default it reduces all dimensions.

    • Default value keepDims: boolean = false

      If true, the moments have the same dimensionality as the input.

    Returns object

    An object with two keys: mean and variance.

multiRNNCell

  • Computes the next states and outputs of a stack of LSTMCells. Each cell output is used as input to the next cell. This is only the forward mode. Derived from tf.contrib.rn.MultiRNNCell.

    Parameters

    • lstmCells: LSTMCell[]

      Array of LSTMCell functions.

    • data: Array2D

      The input to the cell.

    • c: Array2D[]

      Array of previous cell states.

    • h: Array2D[]

      Array of previous cell outputs.

    Returns [Array2D[], Array2D[]]

    Tuple [nextCellStates, cellOutputs]

multinomial

  • Draws samples from a multinomial distribution.

    Parameters

    • probabilities: Array1D | Array2D

      1D array with normalized outcome probabilities, or 2D array of shape [batchSize, numOutcomes].

    • numSamples: number

      Number of samples to draw for each row slice.

    • Optional seed: number

      Optional. The seed number.

    Returns Array1D<"int32"> | Array2D<"int32">

    1D array of shape [numSamples], or 2D array of shape [batchSize, numSamples], depending on the rank of the input.

multiply

  • Multiplies two NDArrays element-wise, A * B. Supports broadcasting. For a stricter version without broadcasting use math.multiplyStrict().

    Parameters

    • a: NDArray

      The first NDArray to multiply element-wise.

    • b: NDArray

      The second NDArray to multiply element-wise.

    Returns NDArray

multiplyStrict

  • multiplyStrict<T>(a: T, b: T): T
  • Multiplies two NDArrays element-wise, A * B. Inputs must be the same shape. For broadcasting support, use math.multiply() instead.

    Type parameters

    Parameters

    • a: T

      The first NDArray to multiply element-wise.

    • b: T

      The second NDArray to multiply element-wise.

    Returns T

neg

  • neg<T>(a: T): T
  • Computes -1 * A element-wise.

    Type parameters

    Parameters

    • a: T

      The input array.

    Returns T

oneHot

  • oneHot(indices: Array1D, depth: number, onValue?: number, offValue?: number): Array2D
  • Returns a one-hot array. The locations represented by indices take value onValue (defaults to 1), while all other locations take value offValue (defaults to 0).

    Parameters

    • indices: Array1D

      1D Array of indices.

    • depth: number

      The depth of the one hot dimension.

    • Default value onValue: number = 1

      A number used to fill in output when the index matches the location.

    • Default value offValue: number = 0

      A number used to fill in the output when the index does not match the location.

    Returns Array2D

outerProduct

  • Computes the outer product of two vectors, v1 and v2.

    Parameters

    • v1: Array1D

      The first vector in the outer product operation.

    • v2: Array1D

      The second vector in the dot product operation.

    Returns Array2D

relu

  • relu<T>(ndarray: T): T
  • Computes rectified linear element-wise, max(x, 0).

    Type parameters

    Parameters

    • ndarray: T

      The input NDArray.

    Returns T

reshape

  • reshape<T1, T2>(ndarray: T1, newShape: number[]): T2
  • deprecated

    Please call reshape() directly on the ndarray object.

    Type parameters

    Parameters

    • ndarray: T1
    • newShape: number[]

    Returns T2

resizeBilinear3D

  • resizeBilinear3D(x: Array3D, newShape2D: [number, number], alignCorners?: boolean): Array3D

scalarDividedByArray

  • scalarDividedByArray<T>(c: Scalar, a: T): T

scalarMinusArray

  • scalarMinusArray<T>(c: Scalar, a: T): T

scalarPlusArray

  • scalarPlusArray<T>(c: Scalar, a: T): T

scalarTimesArray

  • scalarTimesArray<T>(c: Scalar, a: T): T

scaledArrayAdd

  • Computes a scaled array add operation, c1 A + c2 B.

    Type parameters

    Parameters

    • c1: Scalar

      The first scalar in the scaled array add computation.

    • a: T

      The first NDArray in the scaled array add computation.

    • c2: Scalar

      The second scalar in the scaled array add computation.

    • b: T

    Returns T

scope

  • scope<T>(scopeFn: function): T
  • Create a new math scope. Put chained math operations inside a scope function closure so that the library automatically cleans up NDArrays from intermediate math operations. You must create a scope in safe mode to call math operations. If a result is returned from the scope, it will also be tracked, which means there must be yet another wrapping scope.

    Type parameters

    Parameters

    • scopeFn: function

      The function to execute with chained math operations.

        • (keep: function, track: function): T
        • Parameters

          • keep: function
              • <D1, T1>(ndarray: T1): T1
              • Type parameters

                • D1: "float32" | "int32" | "bool"

                • T1: NDArray<D1>

                Parameters

                • ndarray: T1

                Returns T1

          • track: function
              • <D2, T2>(ndarray: T2): T2
              • Type parameters

                • D2: "float32" | "int32" | "bool"

                • T2: NDArray<D2>

                Parameters

                • ndarray: T2

                Returns T2

          Returns T

    Returns T

sigmoid

  • sigmoid<T>(ndarray: T): T
  • Computes sigmoid element-wise, y = 1 / (1 + exp(-x)).

    Type parameters

    Parameters

    • ndarray: T

      The input NDArray.

    Returns T

sin

  • sin<T>(ndarray: T): T
  • Computes sin of the input NDArray element-wise, y = sin(x).

    Type parameters

    Parameters

    • ndarray: T

      The input NDArray.

    Returns T

sinh

  • sinh<T>(ndarray: T): T
  • Computes hyperbolic sin of the input NDArray element-wise, y = sinh(x).

    Type parameters

    Parameters

    • ndarray: T

      The input NDArray.

    Returns T

slice1D

  • Extracts a 1D slice from 1D array starting at coordinates begin and is of length size.

    Parameters

    • input: Array1D

      The input array to slice from.

    • begin: number

      The offset to start the slice from.

    • size: number

      The size of the slice.

    Returns Array1D

slice2D

  • slice2D(input: Array2D, begin: [number, number], size: [number, number]): Array2D
  • Extracts a 2D slice from a 2D array starting at coordinates begin and is of size size.

    Parameters

    • input: Array2D

      The input array to slice from.

    • begin: [number, number]

      The [row, col] 2d coordinates to start the slice from.

    • size: [number, number]

      The size of the slice.

    Returns Array2D

slice3D

  • slice3D(input: Array3D, begin: [number, number, number], size: [number, number, number]): Array3D
  • Extracts a 3D slice from a 3D array starting at coordinates begin and is of size size.

    Parameters

    • input: Array3D

      The input array to slice from.

    • begin: [number, number, number]

      The [row, col, depth] 3d coordinates to start the slice from.

    • size: [number, number, number]

      The size of the slice.

    Returns Array3D

slice4D

  • slice4D(input: Array4D, begin: [number, number, number, number], size: [number, number, number, number]): Array4D
  • Extracts a 4D slice from a 4D array starting at coordinates begin and is of size size.

    Parameters

    • input: Array4D

      The input array to slice from.

    • begin: [number, number, number, number]

      The [row, col, depth, depth2] 4d coordinates to start the slice from.

    • size: [number, number, number, number]

      The size of the slice.

    Returns Array4D

softmax

  • softmax<T>(logits: T, dim?: number): T
  • Computes the softmax normalized vector given the logits.

    Type parameters

    Parameters

    • logits: T

      The logits array.

    • Default value dim: number = -1

      The dimension softmax would be performed on. Defaults to -1 which indicates the last dimension.

    Returns T

sqrt

  • sqrt<T>(ndarray: T): T
  • Computes square root of the input NDArray element-wise. y = sqrt(x)

    Type parameters

    Parameters

    • ndarray: T

      The input NDArray.

    Returns T

square

  • square<T>(x: T): T
  • Computes square of x element-wise.

    Type parameters

    Parameters

    • x: T

      The input array.

    Returns T

startScope

  • startScope(): void
  • Start a scope. Use this with endScope() to achieve the same functionality as scope() without the need for a function closure.

    Returns void

step

  • step<T>(ndarray: T, alpha?: number): T
  • Computes step of the input NDArray element-wise, y=1 if x>0|alpha*x if x<=0.

    Type parameters

    Parameters

    • ndarray: T

      The input NDArray.

    • Default value alpha: number = 0

      The gradient when input is negative.

    Returns T

sub

subStrict

  • subStrict<D, T>(a: T, b: T): T
  • Subtracts two NDArrays element-wise, A - B. Inputs must be the same shape. For broadcasting support, use math.sub() instead.

    Type parameters

    • D: "float32" | "int32" | "bool"

    • T: NDArray<D>

    Parameters

    • a: T

      The first NDArray to multiply element-wise.

    • b: T

      The second NDArray to multiply element-wise.

    Returns T

subtract

  • Subtracts two NDArrays element-wise, A - B. Supports broadcasting. For a stricter version without broadcasting use math.subStrict().

    Type parameters

    • G: "float32" | "int32" | "bool"

    Parameters

    • a: NDArray<G>

      The first NDArray to subtract element-wise.

    • b: NDArray<G>

      The second NDArray to subtract element-wise.

    Returns NDArray<G>

sum

  • sum<T>(input: NDArray<T>, axis?: number | number[], keepDims?: boolean): NDArray<SumTypes[T]>
  • Computes the sum of elements across dimensions of an array.

    Reduces the input along the dimensions given in axes. Unless keepDims is true, the rank of the array is reduced by 1 for each entry in axes. If keepDims is true, the reduced dimensions are retained with length 1. If axes has no entries, all dimensions are reduced, and an array with a single element is returned.

    Type parameters

    • T: "float32" | "int32" | "bool"

    Parameters

    • input: NDArray<T>

      The input array to compute the sum over.

    • Default value axis: number | number[] = null

      Optional. The dimension(s) to reduce. By default it reduces all dimensions.

    • Default value keepDims: boolean = false

      Optional. If true, retains reduced dimensions with size 1.

    Returns NDArray<SumTypes[T]>

switchDim

  • switchDim<T>(a: T, newDim: number[]): T
  • deprecated

    Use math.transpose() instead.

    Type parameters

    Parameters

    • a: T
    • newDim: number[]

    Returns T

tan

  • tan<T>(ndarray: T): T
  • Computes tan of the input NDArray element-wise, y = tan(x).

    Type parameters

    Parameters

    • ndarray: T

      The input NDArray.

    Returns T

tanh

  • tanh<T>(ndarray: T): T
  • Computes hyperbolic tangent of the input NDArray element-wise.

    Type parameters

    Parameters

    • ndarray: T

      The input NDArray.

    Returns T

tile

  • tile<D, T>(a: T, reps: number[]): T
  • Construct an array by repeating it the number of times given by reps.

    This operation creates a new array by replicating input reps times. The output tensor's i'th dimension has input.shape[i] * reps[i] elements, and the values of input are replicated reps[i] times along the i'th dimension. For example, tiling [a, b, c, d] by [2] produces [a, b, c, d, a, b, c, d].

    Type parameters

    • D: "float32" | "int32" | "bool"

    • T: NDArray<D>

    Parameters

    • a: T

      The array to transpose.

    • reps: number[]

      Determines the number of replications per dimension.

    Returns T

topK

  • topK(ndarray: NDArray, k: number): object
  • Computes the top K values and flattened indices.

    Parameters

    • ndarray: NDArray

      The input NDArray.

    • k: number

      How many top values to compute.

    Returns object

track

  • track<G, T>(result: T): T
  • Tracks an NDArray in the current scope to be automatically cleaned up when the current scope ends, and returns the value.

    Type parameters

    • G: "float32" | "int32" | "bool"

    • T: NDArray<G>

    Parameters

    • result: T

      The NDArray to track in the current scope.

    Returns T

transpose

  • transpose<D, T>(a: T, perm?: number[]): T
  • Transposes the array. Permutes the dimensions according to perm.

    The returned array's dimension i will correspond to the input dimension perm[i]. If perm is not given, it is set to [n-1...0], where n is the rank of the input array. Hence by default, this operation performs a regular matrix transpose on 2-D input arrays.

    Type parameters

    • D: "float32" | "int32" | "bool"

    • T: NDArray<D>

    Parameters

    • a: T

      The array to transpose.

    • Optional perm: number[]

      Optional. The permutation of the dimensions of a.

    Returns T

vectorTimesMatrix

  • Computes the dot product of a vector and a matrix, v * B.

    Parameters

    • v: Array1D

      The vector in dot product operation.

    • matrix: Array2D

      The matrix in dot product operation.

    Returns Array1D

Generated using TypeDoc