/// <summary>
 ///     Applies a function to every element of the array.
 /// </summary>
 public static TResult[][] Apply <TInput, TResult>(this TInput[][] matrix, Func <TInput, int, int, TResult> func)
 {
     return(Apply(matrix, func, Jagged.CreateAs <TInput, TResult>(matrix)));
 }
 /// <summary>
 ///   Returns a matrix with a vector of values on its diagonal.
 /// </summary>
 ///
 public static T[][] Diagonal <T>(int rows, int cols, T[] values)
 {
     return(Diagonal(rows, cols, values, Jagged.Create <T>(rows, cols)));
 }
 /// <summary>
 ///   Transforms a vector into a matrix of given dimensions.
 /// </summary>
 ///
 public static T[][] Reshape <T>(T[] array, int rows, int cols, MatrixOrder order = MatrixOrder.Default)
 {
     return(Jagged.Reshape(array, rows, cols, Jagged.Create <T>(rows, cols), order));
 }
 /// <summary>
 ///   Returns a square diagonal matrix of the given size.
 /// </summary>
 ///
 public static T[][] Diagonal <T>(int size, T value)
 {
     return(Diagonal(size, value, Jagged.Create <T>(size, size)));
 }
 /// <summary>
 ///   Return a square matrix with a vector of values on its diagonal.
 /// </summary>
 ///
 public static T[][] Diagonal <T>(T[] values)
 {
     return(Diagonal(values, Jagged.Create <T>(values.Length, values.Length)));
 }
 /// <summary>
 ///   Creates a matrix of k-hot vectors, where all values at each row are
 ///   zero except for the indicated <paramref name="indices"/>, which are set to one.
 /// </summary>
 ///
 /// <param name="indices">The rows's dimension which will be marked as one.</param>
 /// <param name="columns">The size (length) of the vectors (columns of the matrix).</param>
 ///
 /// <returns>A matrix containing k-hot vectors where only elements at the indicated
 ///   <paramref name="indices"/> are set to one and the others are zero.</returns>
 ///
 public static double[][] KHot(int[][] indices, int columns)
 {
     return(KHot(indices, Jagged.Create <double>(indices.Length, columns)));
 }
 /// <summary>
 ///   Creates a matrix of k-hot vectors, where all values at each row are
 ///   zero except for the ones in the positions where <paramref name="mask"/>
 ///   are true, which are set to one.
 /// </summary>
 ///
 /// <param name="mask">The boolean mask determining where ones will be placed.</param>
 /// <param name="columns">The size (length) of the vectors (columns of the matrix).</param>
 ///
 /// <returns>A matrix containing one-hot vectors where only a single position
 ///   is one and the others are zero.</returns>
 ///
 public static double[][] KHot(bool[][] mask, int columns)
 {
     return(KHot(mask, Jagged.Create <double>(mask.Length, columns)));
 }
 /// <summary>
 ///   Creates a matrix of k-hot vectors, where all values at each row are
 ///   zero except for the indicated <paramref name="indices"/>, which are set to one.
 /// </summary>
 ///
 /// <typeparam name="T">The data type for the matrix.</typeparam>
 ///
 /// <param name="indices">The rows's dimension which will be marked as one.</param>
 /// <param name="columns">The size (length) of the vectors (columns of the matrix).</param>
 ///
 /// <returns>A matrix containing k-hot vectors where only elements at the indicated
 ///   <paramref name="indices"/> are set to one and the others are zero.</returns>
 ///
 public static T[][] KHot <T>(int[][] indices, int columns)
 {
     return(KHot <T>(indices, Jagged.Create <T>(indices.Length, columns)));
 }
 /// <summary>
 ///   Creates a matrix of k-hot vectors, where all values at each row are
 ///   zero except for the ones in the positions where <paramref name="mask"/>
 ///   are true, which are set to one.
 /// </summary>
 ///
 /// <typeparam name="T">The data type for the matrix.</typeparam>
 ///
 /// <param name="mask">The boolean mask determining where ones will be placed.</param>
 ///
 /// <returns>A matrix containing one-hot vectors where only a single position
 ///   is one and the others are zero.</returns>
 ///
 public static T[][] KHot <T>(bool[][] mask)
 {
     return(KHot <T>(mask, Jagged.CreateAs <bool, T>(mask)));
 }
 /// <summary>
 ///   Creates a matrix of one-hot vectors, where all values at each row are
 ///   zero except for the ones in the positions where <paramref name="mask"/>
 ///   are true, which are set to one.
 /// </summary>
 ///
 /// <typeparam name="T">The data type for the matrix.</typeparam>
 ///
 /// <param name="mask">The boolean mask determining where ones will be placed.</param>
 ///
 /// <returns>A matrix containing one-hot vectors where only a single position
 ///   is one and the others are zero.</returns>
 ///
 public static T[][] OneHot <T>(bool[] mask)
 {
     return(OneHot <T>(mask, Jagged.Create <T>(mask.Length, 2)));
 }
Exemplo n.º 11
0
 /// <summary>
 ///   Converts the string representation of a matrix to its
 ///   double-precision floating-point number matrix equivalent.
 ///   A return value indicates whether the conversion succeeded or failed.
 /// </summary>
 /// <param name="s">The string representation of the matrix.</param>
 /// <param name="provider">
 ///   The format provider to use in the conversion. Default is to use
 ///   <see cref="DefaultMatrixFormatProvider.CurrentCulture"/>.
 /// </param>
 /// <param name="matrix">A double-precision floating-point number matrix parsed
 /// from the given string using the given format provider.</param>
 /// <result>When this method returns, contains the double-precision floating-point
 /// number matrix equivalent to the <see param="s"/> parameter, if the conversion succeeded, 
 /// or null if the conversion failed. The conversion fails if the <see param="s"/> parameter
 /// is null, is not a matrix in a valid format, or contains elements which represent
 /// a number less than MinValue or greater than MaxValue. This parameter is passed
 /// uninitialized. </result>
 /// 
 public static bool TryParse(string s, IMatrixFormatProvider provider, out double[][] matrix)
 {
     return Jagged.TryParse(s, provider, out matrix);
 }
Exemplo n.º 12
0
 /// <summary>
 ///   Gets the null-space of a column vector.
 /// </summary>
 ///
 public static Double[][] Null(this Double[] vector)
 {
     return(Null(Jagged.ColumnVector(vector)));
 }