c# - Input string was not in a correct format String to double [] [] array -
I know there are more formulas on this topic, but none of these really helps me.
I will provide the whole code:
Namespace console application 1 {public static class load {public static double [] [] from file (string path) {var rows = new List & lt; Double [] & gt; ); Forehack (fernline in file. ReadLine (path)) // Here are the lines of error. Add (line split (new [] {'}}. Select (double. Purse) .oere ()); } Return Lines .ORA (); }} Public class program {static zero main (string [] args) {string cestain = @ "e: \ vstup.txt"; Double [] [] innput = load.from (cestain); String cestaout = @ "e: \ vystup.txt"; Double [] [] ooutput = load. From cestaout; // CRE A TE a neural network var network = new Basic Network (); Networks Adler (new basic layer (empty, truth, 2)); Networks Adler (new Basic Layer (new activation signmide (true), 3)); Networks Adler (new basic layer (new activation signmide (), incorrect, 1)); Networks Structure final form structure (); Networks Reset (); // CRAATTRAININN NG Data IMLDataSet trainingSet = New Original MLDataSet (innput, ooutput); // TRA I EN Neural Network IMLTrain Train = New Flexibility (Network, TrainingSat); Int era = 1; Do {train.Iteration (); Console WrightLine (@ "Epoch #" + epoch + @ "Error:" + train.Error); Era ++; } While (train.Error> 0.01); Console.ReadLine (); }}} I am trying to load in the double [] [] input: 166 163 180 228
165 162 160 226
166 163 180 228 166 164 180 228
171 162 111 225
/ Blockquote>
is that I am attempting to load double [] [] in the output: 1 0 0 0 0 0 0 0 1 0 1 0 0
Problem: You have Extra lines after each line empty lines in your text file when the split () function meets a new line, why Because it is outstanding that there is nothing to divide and the Add () function throws an exception because the blank line is not a valid double Solution 1: You can use StringSplitOptions.RemoveEmptyEntries to clear the Split () function as a second line to clear the blank lines . foreach (File in the file. ReadLine (path)) // // Here are errors rows. Add (line split (new [] {'}}, string split option. Remove remove entries. (Double.Parse) .toArray ()); } Solution 2: You can check if the weather line is empty or not String.IsNullOrWhiteSpace () Pre> foreach (Fernline in file. ReadLine (Path)) {If (string! ISOLOROSWhatSpace (line)) {// Here are the lines of error. Add (line split (new [] {'}}, StringSplitOptions.RemoveEmptyEntries. Select (double.Parse) .toArray ()); }}
Comments
Post a Comment