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
sourcefloat[,]The two-dimensional array to process.
scalarfloatThe 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.
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
sourcefloat[,,,]The four-dimensional array whose elements will be incremented.
scalarfloatThe scalar value to add to each element of the array.
Remarks
This method modifies the contents of the source array directly.
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
sourcefloat[,]The two-dimensional array of single-precision floating-point numbers whose elements will be incremented. Cannot be null.
scalarfloatThe 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.
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
sourcefloat[,]The source two-dimensional array.
matrixfloat[]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.
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
sourcefloat[,]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
sourcefloat[,,,]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
sourcefloat[,]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
sourcefloat[]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
sourcefloat[,,,]The array used only for shape in all four dimensions.
onesProbabilityfloatProbability of placing 1 in a cell. Must be between 0 and 1.
randomRandomThe random number generator instance.
Returns
- float[,,,]
A new array with the same shape as
sourcecontaining 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
sourcefloat[,]The array used only for shape (dim1 and dim2).
onesProbabilityfloatProbability of placing 1 in a cell. Must be between 0 and 1.
randomRandomThe random number generator instance.
Returns
- float[,]
A new array with the same shape as
sourcecontaining 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
sourcefloat[,,,]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
sourcefloat[,]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
sourcefloat[,]The two-dimensional array of single-precision floating-point numbers to be clipped.
minfloatThe minimum value to which elements in the array will be limited.
maxfloatThe 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
sourcefloat[,]The two-dimensional array to clip.
minfloatThe minimum value to clip the source elements to.
maxfloatThe 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
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
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
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
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
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
sourcefloat[,,,]The four-dimensional array to slice.
rowintThe 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
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
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
sourcefloat[,,,]The four-dimensional array to slice.
rangeRangeThe 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
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
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
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
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
sourcefloat[,]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
sourcefloat[,,,]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
sourcefloat[,]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
sourcefloat[,,,]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
sourcefloat[,]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
sourcefloat[,]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
sourcefloat[,,,]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
sourcefloat[,]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
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
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
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
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
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
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
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
sourcefloat[]The one-dimensional array treated as a row vector.
matrixfloat[,]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
sourcefloat[,]The two-dimensional array whose dim1 will be permuted.
seedintThe 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
sourcefloat[,]The two-dimensional array whose dim1 will be permuted.
randomRandomThe 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
sourcefloat[,,,]The four-dimensional array whose dim1 will be permuted in place. The first dimension represents the dim1 to be shuffled.
secondMatrixfloat[,]The two-dimensional matrix whose dim1 will be permuted in place together with the dim1 of
source. Must have the same number of dim1 assource.randomRandomThe 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
sourcefloat[,]The first matrix whose dim1 will be permuted. Must have the same number of dim1 as
secondMatrix.secondMatrixfloat[,]The second matrix whose dim1 will be permuted in tandem with
source. Must have the same number of dim1 assource.randomRandomThe 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
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
sourcefloat[,]The first matrix whose dim1 will be permuted in place. Must have the same number of dim1 as
secondMatrix.secondMatrixfloat[,]The second matrix whose dim1 will be permuted in place together with
source. Must have the same number of dim1 assource.randomRandomThe 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
sourcefloat[,]The two-dimensional array whose elements will be exponentiated.
scalarintThe 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
sourcefloat[,]The two-dimensional array to fill with random values.
seedintThe 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
sourcefloat[,,,]The four-dimensional array to modify.
rowIndexintThe zero-based index along dimension 0 to set.
rowfloat[,,]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
sourcefloat[,]The two-dimensional array to modify.
rowIndexintThe index of the row to set.
rowfloat[]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
sourcefloat[,]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
sourcefloat[,]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
sourcefloat[,]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
sourcefloat[,]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
sourcefloat[,]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 insource.
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
Returns
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
sourcefloat[,]The source to standardize.
columnRangeRange?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
sourcefloat[,]The source to standardize.
columnRangeRange?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
sourcefloat[,,,]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
sourcefloat[,]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
sourcefloat[,,,]The minuend array.
matrixfloat[,,,]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
sourcefloat[,]The two-dimensional minuend array.
matrixfloat[,]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
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
sourcefloat[,,,]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
sourcefloat[,]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
sourcefloat[,]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
sourcefloat[,,,]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
sourcefloat[,]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
sourcefloat[,]The two-dimensional array to transpose.
Returns
- float[,]
A new array with shape [dim2, dim1].