Table of Contents

Class ArrayExtensions

Namespace
NeuralNetworks.Core
Assembly
NeuralNetworks.dll

Provides extension methods for performing mathematical and utility operations on multidimensional arrays of type float. These methods enable elementwise arithmetic, statistical calculations, source manipulation, and other common operations for arrays and matrices.

public static class ArrayExtensions
Inheritance
ArrayExtensions
Inherited Members

Remarks

The ArrayExtensions class includes methods for both in-place and out-of-place operations, supporting 1D, 2D, and 4D float arrays. It offers functionality such as elementwise addition, multiplication, subtraction, standardization, transposition, and application of activation functions (e.g., sigmoid, softmax, tanh). Methods are designed to simplify array manipulation in numerical and machine learning scenarios. Thread safety is not guaranteed; callers should synchronize access if arrays are shared across threads.

Methods

Add(float[,], float)

Adds a scalar value to each element of the source.

public static float[,] Add(this float[,] source, float scalar)

Parameters

source float[,]

The two-dimensional array to process.

scalar float

The value to add to each element.

Returns

float[,]

A new array of the same shape with the result of addition.

Remarks

This method creates a new array and does not modify the original source array.

Complexity: O(n * m), where n = dim1 of source, m = dim2 of source.

AddInPlace(float[,,,], float)

Adds the specified scalar value to each element of the four-dimensional array in place.

public static void AddInPlace(this float[,,,] source, float scalar)

Parameters

source float[,,,]

The four-dimensional array whose elements will be incremented.

scalar float

The scalar value to add to each element of the array.

Remarks

This method modifies the contents of the source array directly.

Complexity: O(a * b * c * d) for dimensions of source.

AddInPlace(float[,], float)

Adds the specified scalar value to each element of the two-dimensional array in place.

public static void AddInPlace(this float[,] source, float scalar)

Parameters

source float[,]

The two-dimensional array of single-precision floating-point numbers whose elements will be incremented. Cannot be null.

scalar float

The scalar value to add to each element of the array.

Remarks

This method modifies the contents of the source array directly. The array must be initialized before calling this method.

Complexity: O(n * m), where n = dim1 of source, m = dim2 of source.

AddRow(float[,], float[])

Adds a row to the current source by elementwise addition with the specified source.

public static float[,] AddRow(this float[,] source, float[] matrix)

Parameters

source float[,]

The source two-dimensional array.

matrix float[]

The row values to be added elementwise to each row of the source. Length must equal the number of dim2.

Returns

float[,]

A new array containing the elementwise sum of each row with matrix.

Remarks

This method creates a new array and does not modify the original source array. It adds matrix to each row of source elementwise.

Complexity: O(n * m), where n = dim1 of source, m = dim2 of source.

Argmax(float[,])

Computes the index of the maximum value for each row.

public static int[] Argmax(this float[,] source)

Parameters

source float[,]

The two-dimensional array to evaluate.

Returns

int[]

An array of length equal to the number of dim1, where each element is the column index of the maximum value in that row.

AsOnes(float[,,,])

Creates a new source filled with ones, with the same dimensions as the specified source.

public static float[,,,] AsOnes(this float[,,,] source)

Parameters

source float[,,,]

The source used to determine the dimensions of the new source.

Returns

float[,,,]

A new source filled with ones.

AsOnes(float[,])

Creates a new source filled with ones, with the same dimensions as the specified source.

public static float[,] AsOnes(this float[,] source)

Parameters

source float[,]

The source used to determine the dimensions of the new source.

Returns

float[,]

A new source filled with ones.

AsOnes(float[])

Creates a new one-dimensional array filled with ones, with the same length as the specified source.

public static float[] AsOnes(this float[] source)

Parameters

source float[]

The one-dimensional array used to determine the length of the new array.

Returns

float[]

A new one-dimensional array filled with ones.

Remarks

Example:

float[] source = new float[] { 2.0f, 3.0f, 4.0f };
var res = source.AsOnes(); // returns new float[] { 1.0f, 1.0f, 1.0f }

AsZeroOnes(float[,,,], float, Random)

Creates a new four-dimensional array with elements set to 1 with probability onesProbability, otherwise 0.

public static float[,,,] AsZeroOnes(this float[,,,] source, float onesProbability, Random random)

Parameters

source float[,,,]

The array used only for shape in all four dimensions.

onesProbability float

Probability of placing 1 in a cell. Must be between 0 and 1.

random Random

The random number generator instance.

Returns

float[,,,]

A new array with the same shape as source containing zeros and ones.

AsZeroOnes(float[,], float, Random)

Creates a new two-dimensional array with elements set to 1 with probability onesProbability, otherwise 0.

public static float[,] AsZeroOnes(this float[,] source, float onesProbability, Random random)

Parameters

source float[,]

The array used only for shape (dim1 and dim2).

onesProbability float

Probability of placing 1 in a cell. Must be between 0 and 1.

random Random

The random number generator instance.

Returns

float[,]

A new array with the same shape as source containing zeros and ones.

AsZeros(float[,,,])

Creates a new four-dimensional zero-filled array with the same shape as the source.

public static float[,,,] AsZeros(this float[,,,] source)

Parameters

source float[,,,]

The array used only for shape.

Returns

float[,,,]

A new zero-filled array.

AsZeros(float[,])

Creates a new two-dimensional zero-filled array with the same shape as the source.

public static float[,] AsZeros(this float[,] source)

Parameters

source float[,]

The array used only for shape.

Returns

float[,]

A new zero-filled array.

Clip(float[,], float, float)

Returns a new two-dimensional array with each element of the source array limited to the specified minimum and maximum values.

public static float[,] Clip(this float[,] source, float min, float max)

Parameters

source float[,]

The two-dimensional array of single-precision floating-point numbers to be clipped.

min float

The minimum value to which elements in the array will be limited.

max float

The maximum value to which elements in the array will be limited.

Returns

float[,]

A new two-dimensional array where each element is set to the corresponding value from the source array, limited to the specified minimum and maximum values.

Remarks

If an element in the source array is less than the specified minimum, the result will contain the minimum value at that position. If an element is greater than the specified maximum, the result will contain the maximum value. The original array is not modified.

ClipInPlace(float[,], float, float)

Clips the values of the source in-place between the specified minimum and maximum values.

public static void ClipInPlace(this float[,] source, float min, float max)

Parameters

source float[,]

The two-dimensional array to clip.

min float

The minimum value to clip the source elements to.

max float

The maximum value to clip the source elements to.

Divide(float[,], float)

Divides each element of the two-dimensional array by a scalar and returns a new array.

public static float[,] Divide(this float[,] source, float scalar)

Parameters

source float[,]

The array whose elements will be divided.

scalar float

The divisor.

Returns

float[,]

A new array containing the division results.

DivideInPlace(float[,,,], float)

Divides each element of the four-dimensional array by a scalar in place.

public static void DivideInPlace(this float[,,,] source, float scalar)

Parameters

source float[,,,]

The array to modify.

scalar float

The divisor.

DivideInPlace(float[,], float)

Divides each element of the two-dimensional array by a scalar in place.

public static void DivideInPlace(this float[,] source, float scalar)

Parameters

source float[,]

The array to modify.

scalar float

The divisor.

GetColumn(float[,], int)

Gets a submatrix containing the specified column from the current source. The shape is [dim1, 1].

public static float[,] GetColumn(this float[,] source, int column)

Parameters

source float[,]

The array to slice.

column int

The zero-based column index.

Returns

float[,]

A new [dim1, 1] array representing the selected column.

GetColumns(float[,], Range)

Gets a submatrix containing the specified range of dim2 from the current source. The shape is [dim1, range].

public static float[,] GetColumns(this float[,] source, Range range)

Parameters

source float[,]

The array to slice.

range Range

The range specifying the subset of dim2.

Returns

float[,]

A new array with [dim1, selectedColumns].

GetRow(float[,,,], int)

Gets a three-dimensional slice (row) from a four-dimensional array at the specified first-dimension index.

public static float[,,] GetRow(this float[,,,] source, int row)

Parameters

source float[,,,]

The four-dimensional array to slice.

row int

The zero-based index along dimension 0.

Returns

float[,,]

A new three-dimensional array with shape [dim2, dim3, dim4] containing the selected row.

GetRow(float[,], int)

Gets a row from the source.

public static float[] GetRow(this float[,] source, int row)

Parameters

source float[,]

The two-dimensional array to slice.

row int

The index of the row to retrieve.

Returns

float[]

A new array representing the specified row.

Remarks

The returned row is a new instance and has the same number of dim2 as the original source.

GetRowAs2D(float[,], int)

Gets the specified row as a two-dimensional array with shape [1, dim2].

public static float[,] GetRowAs2D(this float[,] source, int row)

Parameters

source float[,]

The two-dimensional array to slice.

row int

The zero-based row index.

Returns

float[,]

A new [1, dim2] array containing the row values.

GetRows(float[,,,], Range)

Gets a contiguous range of dim1 (dimension 0) from a four-dimensional array.

public static float[,,,] GetRows(this float[,,,] source, Range range)

Parameters

source float[,,,]

The four-dimensional array to slice.

range Range

The range applied to dimension 0.

Returns

float[,,,]

A new four-dimensional array containing the selected dim1.

GetRows(float[,], Range)

Gets a submatrix containing the specified range of dim1 from the current source.

public static float[,] GetRows(this float[,] source, Range range)

Parameters

source float[,]

The array to slice.

range Range

The range of dim1 to retrieve.

Returns

float[,]

A new array representing the submatrix.

Remarks

The returned columns are the same as in the original source.

HasSameShape(float[,,,], float[,,,])

Checks whether two four-dimensional arrays have the same shape across all dimensions.

public static bool HasSameShape(this float[,,,] source, float[,,,] matrix)

Parameters

source float[,,,]

The first array.

matrix float[,,,]

The second array.

Returns

bool

True if all corresponding dimensions are equal; otherwise false.

HasSameShape(float[,], float[,])

Checks whether two two-dimensional arrays have the same shape (dim1 and dim2).

public static bool HasSameShape(this float[,] source, float[,] matrix)

Parameters

source float[,]

The first array.

matrix float[,]

The second array.

Returns

bool

True if both arrays have equal dim1 and dim2; otherwise false.

HasSameShape(float[], float[])

Checks whether two one-dimensional arrays have the same shape (length).

public static bool HasSameShape(this float[] source, float[] matrix)

Parameters

source float[]

The first array.

matrix float[]

The second array.

Returns

bool

True if both arrays have equal length; otherwise false.

Log(float[,])

Computes the natural logarithm elementwise and returns a new array.

public static float[,] Log(this float[,] source)

Parameters

source float[,]

The array whose elements will be transformed.

Returns

float[,]

A new array with log(x) applied elementwise.

Max(float[,,,])

Returns the maximum element value across all elements of a four-dimensional array.

public static float Max(this float[,,,] source)

Parameters

source float[,,,]

The array to scan.

Returns

float

The maximum value found.

Max(float[,])

Returns the maximum element value across all elements of a two-dimensional array.

public static float Max(this float[,] source)

Parameters

source float[,]

The array to scan.

Returns

float

The maximum value found.

Mean(float[,,,])

Calculates the mean of all elements in the source.

public static float Mean(this float[,,,] source)

Parameters

source float[,,,]

The array whose mean will be computed.

Returns

float

The arithmetic mean of all elements.

Mean(float[,])

Calculates the mean of all elements in the source.

public static float Mean(this float[,] source)

Parameters

source float[,]

The array whose mean will be computed.

Returns

float

The arithmetic mean of all elements.

MeanByColumn(float[,])

Calculates the mean of each column in the source.

public static float[] MeanByColumn(this float[,] source)

Parameters

source float[,]

The two-dimensional array to process.

Returns

float[]

A one-dimensional array where each element is the mean of a column.

Min(float[,,,])

Returns the minimum element value across all elements of a four-dimensional array.

public static float Min(this float[,,,] source)

Parameters

source float[,,,]

The array to scan.

Returns

float

The minimum value found.

Min(float[,])

Returns the minimum element value across all elements of a two-dimensional array.

public static float Min(this float[,] source)

Parameters

source float[,]

The array to scan.

Returns

float

The minimum value found.

Multiply(float[,,,], float)

Multiplies each element of the source by a scalar value.

public static float[,,,] Multiply(this float[,,,] source, float scalar)

Parameters

source float[,,,]

The four-dimensional array to multiply.

scalar float

The multiplier.

Returns

float[,,,]

A new array with each element multiplied by the scalar value.

Multiply(float[,], float)

Multiplies each element of the source by a scalar value.

public static float[,] Multiply(this float[,] source, float scalar)

Parameters

source float[,]

The array whose elements will be multiplied.

scalar float

The multiplier.

Returns

float[,]

A new array with the multiplication results.

Multiply(float[], float)

Multiplies each element of the source by a scalar value.

public static float[] Multiply(this float[] source, float scalar)

Parameters

source float[]

The one-dimensional array to multiply.

scalar float

The multiplier.

Returns

float[]

A new array containing the multiplication results.

Remarks

Complexity: O(n * m), where n = dim1 of source, m = dim2 of source

MultiplyByTanhDerivative(float[,,,], float[,,,])

public static float[,,,] MultiplyByTanhDerivative(this float[,,,] outputGradient, float[,,,] output)

Parameters

outputGradient float[,,,]
output float[,,,]

Returns

float[,,,]

MultiplyDot(float[,], float[,])

Multiplies the current source with another source using the dot product.

public static float[,] MultiplyDot(this float[,] source, float[,] matrix)

Parameters

source float[,]

Left operand with shape [n, m].

matrix float[,]

Right operand with shape [m, p].

Returns

float[,]

A new array with shape [n, p] containing the dot product result.

Remarks

Complexity: O(n * m * p), where n = dim1 of source, m = shared dimension, p = dim2 of matrix

MultiplyElementwise(float[,,,], float[,,,])

Performs elementwise multiplication between this source and another source.

public static float[,,,] MultiplyElementwise(this float[,,,] source, float[,,,] matrix)

Parameters

source float[,,,]

The left operand.

matrix float[,,,]

The source to multiply elementwise with.

Returns

float[,,,]

A new source resulting from the elementwise multiplication.

Remarks

Multiplies each element of the source with the corresponding element of another source. If the dimensions of the two matrices are not the same, the smaller source is broadcasted to match the larger source. If the size of this source is (a * b * c * d), and the size of source is (e * f * g * h), then the resulting size is (max(a,e) * max(b,f) * max(c,g) * max(d,h))

MultiplyElementwise(float[,], float[,])

Performs elementwise multiplication between this source and another source.

public static float[,] MultiplyElementwise(this float[,] source, float[,] matrix)

Parameters

source float[,]

The left operand.

matrix float[,]

The source to multiply elementwise with.

Returns

float[,]

A new source resulting from the elementwise multiplication.

Remarks

Multiplies each element of the source with the corresponding element of another source. If the dimensions of the two matrices are not the same, the smaller source is broadcasted to match the larger source. If the size of this source is (a * b), and the size of source is (c * d), then the resulting size is (max(a,c) * max(b,d))

MultiplyElementwise(float[], float[,])

Performs elementwise multiplication between a vector and a matrix, with broadcasting across dim1.

public static float[,] MultiplyElementwise(this float[] source, float[,] matrix)

Parameters

source float[]

The one-dimensional array treated as a row vector.

matrix float[,]

The two-dimensional array to multiply elementwise.

Returns

float[,]

A new two-dimensional array of shape [dim1 of matrix, max(dim2)] containing the elementwise product.

Remarks

If the dimensions are not the same, the smaller array is broadcasted across dim2.

PermuteInPlace(float[,], int)

Randomly permutes the dim1 of the source in-place using the specified seed. It uses the Fisher-Yates shuffle algorithm.

public static void PermuteInPlace(this float[,] source, int seed)

Parameters

source float[,]

The two-dimensional array whose dim1 will be permuted.

seed int

The seed used to initialize the random number generator.

Remarks

Complexity: O(n * m), where n = dim1, m = dim2.

PermuteInPlace(float[,], Random?)

Randomly permutes the dim1 of the source in-place using the provided random instance (Fisher-Yates shuffle).

public static void PermuteInPlace(this float[,] source, Random? random)

Parameters

source float[,]

The two-dimensional array whose dim1 will be permuted.

random Random

The random number generator. If null, a new instance is created.

PermuteInPlaceTogetherWith(float[,,,], float[,], Random?)

Randomly permutes the dim1 of the specified four-dimensional array and the corresponding dim1 of the second matrix in place, ensuring that both arrays are shuffled together using the same permutation.

public static void PermuteInPlaceTogetherWith(this float[,,,] source, float[,] secondMatrix, Random? random)

Parameters

source float[,,,]

The four-dimensional array whose dim1 will be permuted in place. The first dimension represents the dim1 to be shuffled.

secondMatrix float[,]

The two-dimensional matrix whose dim1 will be permuted in place together with the dim1 of source. Must have the same number of dim1 as source.

random Random

The random number generator used to determine the permutation order. If null, a new instance of Random will be created.

Remarks

Both source and secondMatrix must have the same number of dim1; otherwise, the method will not perform a valid permutation. The permutation is performed in place and affects the original arrays. This method is useful for maintaining alignment between related datasets when shuffling.

PermuteInPlaceTogetherWith(float[,], float[,], Random?)

Randomly permutes the dim1 of the specified matrices in place, ensuring that corresponding dim1 in both matrices remain aligned.

public static void PermuteInPlaceTogetherWith(this float[,] source, float[,] secondMatrix, Random? random)

Parameters

source float[,]

The first matrix whose dim1 will be permuted. Must have the same number of dim1 as secondMatrix.

secondMatrix float[,]

The second matrix whose dim1 will be permuted in tandem with source. Must have the same number of dim1 as source.

random Random

The random number generator used to determine the permutation order. If null, a new instance will be created.

Remarks

This method performs an in-place permutation of the dim1 of both matrices, maintaining the correspondence between dim1. This is useful when shuffling paired data, such as features and labels, for machine learning tasks. The operation modifies the input matrices directly.

This method is the quickest for permuting two 2D matrices together.

PermuteInPlaceTogetherWithSetRow(float[,,,], float[,], Random?)

public static void PermuteInPlaceTogetherWithSetRow(this float[,,,] source, float[,] secondMatrix, Random? random)

Parameters

source float[,,,]
secondMatrix float[,]
random Random

PermuteInPlaceTogetherWithSetRow(float[,], float[,], Random?)

Randomly permutes the dim1 of the specified matrices in place, ensuring that corresponding dim1 in both matrices remain aligned after permutation.

public static void PermuteInPlaceTogetherWithSetRow(this float[,] source, float[,] secondMatrix, Random? random)

Parameters

source float[,]

The first matrix whose dim1 will be permuted in place. Must have the same number of dim1 as secondMatrix.

secondMatrix float[,]

The second matrix whose dim1 will be permuted in place together with source. Must have the same number of dim1 as source.

random Random

The random number generator used to determine the permutation order. If null, a new instance will be created.

Remarks

This method performs a Fisher–Yates shuffle on the dim1 of both matrices, maintaining the correspondence between dim1. This is useful when shuffling paired datasets, such as features and labels, to preserve their alignment. Both matrices must have the same number of dim1; otherwise, the behavior is undefined.

Power(float[,], int)

Raises each element of the source to the specified power.

public static float[,] Power(this float[,] source, int scalar)

Parameters

source float[,]

The two-dimensional array whose elements will be exponentiated.

scalar int

The exponent (integer).

Returns

float[,]

A new array with each element raised to scalar.

RandomInPlace(float[,], int)

Fills the source with random float values between -0.5 and 0.5 using the specified seed.

public static void RandomInPlace(this float[,] source, int seed)

Parameters

source float[,]

The two-dimensional array to fill with random values.

seed int

The seed used to initialize the random number generator.

SetRow(float[,,,], int, float[,,])

Sets the three-dimensional row slice at the specified index in a four-dimensional array.

public static void SetRow(this float[,,,] source, int rowIndex, float[,,] row)

Parameters

source float[,,,]

The four-dimensional array to modify.

rowIndex int

The zero-based index along dimension 0 to set.

row float[,,]

A three-dimensional array with shape [dim2, dim3, dim4] providing values.

SetRow(float[,], int, float[])

Sets the values of a specific row in the source.

public static void SetRow(this float[,] source, int rowIndex, float[] row)

Parameters

source float[,]

The two-dimensional array to modify.

rowIndex int

The index of the row to set.

row float[]

The array containing the values to set. Length must equal the number of dim2.

Exceptions

Debug

Asserts when the row index is out of bounds or lengths mismatch.

Sigmoid(float[,])

Applies the sigmoid function to each element of the source.

public static float[,] Sigmoid(this float[,] source)

Parameters

source float[,]

The two-dimensional array to transform.

Returns

float[,]

A new source with each element transformed by the sigmoid function with the same dimensions as the original source.

SigmoidDerivative(float[,])

Calculates the derivative of the sigmoid function for each element of the source.

public static float[,] SigmoidDerivative(this float[,] source)

Parameters

source float[,]

The two-dimensional array to transform.

Returns

float[,]

A new source with each element transformed by the derivative of the sigmoid function with the same dimensions as the original source.

Remarks

The derivative of the sigmoid function is calculated as: sigmoid(x) * (1 - sigmoid(x)).

Softmax(float[,])

Applies the softmax function to the source.

public static float[,] Softmax(this float[,] source)

Parameters

source float[,]

The two-dimensional array to transform (softmax applied per row).

Returns

float[,]

A new source with softmax-applied values.

Remarks

Softmax formula: exp(x) / sum(exp(x)).

SoftmaxLogSumExp(float[,])

Applies the softmax function (with log-sum-exp trick) to the source.

public static float[,] SoftmaxLogSumExp(this float[,] source)

Parameters

source float[,]

The two-dimensional array to transform (log-sum-exp softmax applied per row).

Returns

float[,]

A new source with softmax-applied values.

Remarks

The trick improves numerical stability by subtracting the maximum value in each row before exponentiation. This prevents overflow issues when dealing with large input values.

Softplus(float[,])

Applies the Softplus activation function to each element of the specified two-dimensional array.

public static float[,] Softplus(this float[,] source)

Parameters

source float[,]

A two-dimensional array of single-precision floating-point values to which the Softplus function will be applied.

Returns

float[,]

A two-dimensional array of the same dimensions as source, where each element is the result of applying the Softplus function to the corresponding element in source.

Remarks

The Softplus function is defined as log(1 + exp(x)) and is commonly used as a smooth approximation to the ReLU activation in machine learning applications. The returned array is a new instance; the input array is not modified.

SplitRowsByRatio(float[,], float)

Splits the source into two sets of dim1 based on the specified ratio.

public static (float[,] Set1, float[,] Set2) SplitRowsByRatio(this float[,] source, float ratio)

Parameters

source float[,]

The two-dimensional array to split.

ratio float

The ratio for splitting the dim1.

Returns

(float[,] Set1, float[,] Set2)

A tuple containing the two sets of dim1.

Standardize(float[,], Range?)

Standardizes the source in-place so that each column (or a specified range of dim2) has a mean of 0 and a standard deviation of 1 by applying the (x - mean) / stdDev transformation.

public static void Standardize(this float[,] source, Range? columnRange = null)

Parameters

source float[,]

The source to standardize.

columnRange Range?

Optional. The range of dim2 to standardize. If null, all dim2 are standardized.

Remarks

Standard deviation is calculated using the formula: sqrt(sum((x - mean)^2) / N), where N is the number of dim1.

StandardizeSinglePass(float[,], Range?)

Standardizes the source in-place so that each column (or a specified range of dim2) has mean 0 and standard deviation 1, computed in a single pass.

public static void StandardizeSinglePass(this float[,] source, Range? columnRange = null)

Parameters

source float[,]

The source to standardize.

columnRange Range?

Optional. The range of dim2 to standardize. If null, all dim2 are standardized.

StdDev(float[,,,])

Calculates the standard deviation for all elements of a four-dimensional array.

public static float StdDev(this float[,,,] source)

Parameters

source float[,,,]

The array whose standard deviation will be computed.

Returns

float

The standard deviation of all elements.

Remarks

Standard deviation is calculated using the formula: sqrt(sum((x - mean)^2) / N), where N is the number of all elements in the array.

StdDev(float[,])

Calculates the standard deviation for all elements of a two-dimensional array.

public static float StdDev(this float[,] source)

Parameters

source float[,]

The array whose standard deviation will be computed.

Returns

float

The standard deviation of all elements.

Remarks

Standard deviation is calculated using the formula: sqrt(sum((x - mean)^2) / N), where N is the number of all elements in the array.

Subtract(float[,,,], float[,,,])

Subtracts the elements of the specified four-dimensional array from the current four-dimensional array.

public static float[,,,] Subtract(this float[,,,] source, float[,,,] matrix)

Parameters

source float[,,,]

The minuend array.

matrix float[,,,]

The subtrahend array. Must have the same shape as source.

Returns

float[,,,]

A new array containing the elementwise difference.

Subtract(float[,], float[,])

Subtracts the elements of the specified source from the current source.

public static float[,] Subtract(this float[,] source, float[,] matrix)

Parameters

source float[,]

The two-dimensional minuend array.

matrix float[,]

The two-dimensional subtrahend array. Must have the same shape.

Returns

float[,]

A new array containing the elementwise difference.

Subtract(float[], float[])

Subtracts the elements of the specified one-dimensional array from the current one-dimensional array.

public static float[] Subtract(this float[] source, float[] matrix)

Parameters

source float[]

The minuend array.

matrix float[]

The subtrahend array. Must have the same length.

Returns

float[]

A new array containing the elementwise difference.

Sum(float[,,,])

Calculates the sum of all elements in the four-dimensional array.

public static float Sum(this float[,,,] source)

Parameters

source float[,,,]

The array to sum.

Returns

float

The sum of all elements.

Sum(float[,])

Calculates the sum of all elements in the two-dimensional array.

public static float Sum(this float[,] source)

Parameters

source float[,]

The array to sum.

Returns

float

The sum of all elements.

SumByColumns(float[,])

Calculates the sum of each column in the source.

public static float[] SumByColumns(this float[,] source)

Parameters

source float[,]

The two-dimensional array to process.

Returns

float[]

A one-dimensional array where each element is the sum of a column.

Tanh(float[,,,])

Applies the hyperbolic tangent function element-wise to the source.

public static float[,,,] Tanh(this float[,,,] source)

Parameters

source float[,,,]

The four-dimensional array to transform.

Returns

float[,,,]

A new source with the hyperbolic tangent applied element-wise.

Tanh(float[,])

Applies the hyperbolic tangent function element-wise to the source.

public static float[,] Tanh(this float[,] source)

Parameters

source float[,]

The two-dimensional array to transform.

Returns

float[,]

A new source with the hyperbolic tangent applied element-wise.

Transpose(float[,])

Transposes the source by swapping its dim1 and dim2.

public static float[,] Transpose(this float[,] source)

Parameters

source float[,]

The two-dimensional array to transpose.

Returns

float[,]

A new array with shape [dim2, dim1].