/// <summary> /// Applies a function transformation on all of the set's items /// </summary> /// <param name="s">A set of numbers</param> /// <param name="f">A function that will be used for transformation. Function takes one parameter and returns a number</param> public static Set Transform(Set s, OneParamFunction f) { Set ret = new Set(); for (int i = 0; i < s.Count; i++) { ret.Add(f(s[i])); } return(ret); }
/// <summary> /// Applies a function transformation on the items of a matrix /// </summary> /// <param name="matrix"></param> /// <param name="f">A function that will be used for transformation. Function takes one parameter and returns a number</param> public static DenseMatrix Transform(DenseMatrix matrix, OneParamFunction f) { DenseMatrix ret = new DenseMatrix(matrix.RowCount, matrix.ColumnCount); for (int i = 0; i < ret.RowCount; i++) { for (int j = 0; j < ret.ColumnCount; j++) { ret[i, j] = f(matrix[i, j]); } } return(ret); }