public NDArrayGeneric <T> inv() { NDArrayGeneric <T> npInv = new NDArrayGeneric <T>(); npInv.Shape = new Shape(this.Shape.Shapes); npInv.Data = new T[this.Data.Length]; switch (this) { case NDArrayGeneric <double> np: { NDArrayGeneric <double> npInvDouble = npInv as NDArrayGeneric <double>; double[][] matrix = np.ToDotNetArray <double[][]>(); double[][] matrixInv = MatrixInv.InverseMatrix(matrix); for (int idx = 0; idx < npInv.Shape.Shapes[0]; idx++) { for (int jdx = 0; jdx < npInv.Shape.Shapes[1]; jdx++) { npInvDouble[idx, jdx] = matrixInv[idx][jdx]; } } break; } default: { throw new Exception("This method was not implemented for this Type : " + typeof(T).Name); } } return(npInv); }
public NDArray inv() { var npInv = new NDArray(this.Storage.DType, this.shape); Array matrixStorage = this.Storage.GetData(); Array invStorage = Array.CreateInstance(npInv.Storage.DType, matrixStorage.Length); switch (matrixStorage) { case double[] np: { double[][] matrix = new double[this.Storage.Shape.Dimensions[0]][]; for (int idx = 0; idx < matrix.Length; idx++) { matrix[idx] = new double[this.Storage.Shape.Dimensions[1]]; for (int jdx = 0; jdx < matrix[idx].Length; jdx++) { matrix[idx][jdx] = np[this.Storage.Shape.GetIndexInShape(idx, jdx)]; } } double[][] matrixInv = MatrixInv.InverseMatrix(matrix); double[] invArray = invStorage as double[]; for (int idx = 0; idx < npInv.shape[0]; idx++) { for (int jdx = 0; jdx < npInv.shape[1]; jdx++) { invArray[this.Storage.Shape.GetIndexInShape(idx, jdx)] = matrixInv[idx][jdx]; } } break; } default: { throw new IncorrectTypeException(); } } npInv.Storage.SetData(invStorage); return(npInv); }
public static NDArray <double> Inv(this NDArray <double> np) { double[][] matrix = np.ToDotNetArray <double[][]>(); double[][] matrixInv = MatrixInv.InverseMatrix(matrix); NDArray <double> npInv = new NDArray <double>().Zeros(np.Shape[0], np.Shape[1]); for (int idx = 0; idx < npInv.Shape[0]; idx++) { for (int jdx = 0; jdx < npInv.Shape[1]; jdx++) { npInv[idx, jdx] = matrixInv[idx][jdx]; } } return(npInv); }