I'm having problems filling a 2D array with a matrix from a text file using GO.
The main problem I have is to create a 2D array because I have to calculate the dimension of the array and GO does not seem to accept VAR in array dimension :
nb_lines = number of line of the array
nb_col = number of columns of the array
// read matrix from file
whole_file,_ := ioutil.ReadFile("test2.txt")
// get each line of the file in tab_whole_file
tab_whole_file := strings.Split(string(whole_file), "
")
// first line of the table
tab_first_line := strings.Split(tab_whole_file[0], "\t")
nb_col := len(tab_first_line)
nb_lines := len(tab_whole_file) - 1
// at this point I tried to build a array to contain the matrix values from the texte file
var columns [nb_lines][nb_col]float64 // does not work
columns := make([][]float64, nb_lines, nb_col) // does not work
columns := make([nb_lines][nb_col]float64) // does not work
columns := [nb_lines][nb_col]float64{} // does not work
columns := [][]float64{} // panic: runtime error: index out of range
for i := 0; i < nb_lines ; i++ { // for each line of the table from text file
line := strings.Split(tab_whole_file[0], "\t") // split one line to get each table values
for j := 1; j < len(line) ; j++ {
columns[i][j], _ = strconv.ParseFloat(line[j], 64) // assign each value to the table columns[i][j]
}
}