将每个值动态附加到GOLANG中的2D切片中

I wish to have a datastructure(array or slice) to look like this :

[[a b c d e][f g h i j] [k l m n o] [p q r s t] [u v w x y]] 

such that a is the distance between node from "A" to "A" . (which shall be 0) b is the distance between node from "A" to "B" . c is the distance between node from "A" to "C" .

f is the distance between node from "B" to "A" . g is the distance between node from "B" to "B" . (which shall be 0) h is the distance between node from "B" to "C" .

Now I have created a slice like : var shortestPathSLice = make([][]int, 5) to store this 2D data.

In my for loop within a function, I am trying to fill this slice dynamically as follows :

shortestPathSLice = append(shortestPathSLice[0][index], lowEstimate[0])

where lowestimate[0] is value of the smallest distances between two nodes.

However, I get an error with this : first argument to append must be slice; have int

Can anyone tell me how can I dynamically append values in EACH ELEMENT in my slice ?

**CODE **

    var shortestPathSLice = make([][]int, 5)
    for index := 0; index < len(t.Location_ids); index++ {
    lowEstimate := make([]int, len(priceestimatestruct.Prices))
        for i := 0; i < len(priceestimatestruct.Prices); i++ {
            lowEstimate[i] = priceestimatestruct.Prices[i].LowEstimate
        }

        sort.Ints(lowEstimate)
        fmt.Println("LowEstimate array : ", lowEstimate)
        shortestPathSLice[0] = make([]int, len(lowEstimate))
        shortestPathSLice[0][index] = lowEstimate[0]
}

The Go Programming Language Specification

Appending to and copying slices

The built-in functions append and copy assist in common slice operations. For both functions, the result is independent of whether the memory referenced by the arguments overlaps.

The variadic function append appends zero or more values x to s of type S, which must be a slice type, and returns the resulting slice, also of type S. The values x are passed to a parameter of type ...T where T is the element type of S and the respective parameter passing rules apply. As a special case, append also accepts a first argument assignable to type []byte with a second argument of string type followed by .... This form appends the bytes of the string.

append(s S, x ...T) S  // T is the element type of S

If the capacity of s is not large enough to fit the additional values, append allocates a new, sufficiently large underlying array that fits both the existing slice elements and the additional values. Otherwise, append re-uses the underlying array.

For example, using append and using an index,

package main

import "fmt"

func main() {
    { // using append
        dim := 5
        matrix := make([][]int, dim) // dim*dim matrix
        for i := 0; i < dim; i++ {
            matrix[i] = make([]int, 0, dim)
            vector := make([]int, dim)
            for j := 0; j < dim; j++ {
                vector[j] = i*dim + j
                matrix[i] = append(matrix[i], vector[j])
            }
        }
        fmt.Println(matrix)
    }
    { // using index
        dim := 5
        matrix := make([][]int, dim) // dim*dim matrix
        for i := range matrix {
            matrix[i] = make([]int, dim)
            vector := make([]int, dim)
            for j := range matrix[i] {
                vector[j] = i*dim + j
                matrix[i][j] = vector[j]
            }
        }
        fmt.Println(matrix)
    }
}

Output:

[[0 1 2 3 4] [5 6 7 8 9] [10 11 12 13 14] [15 16 17 18 19] [20 21 22 23 24]]
[[0 1 2 3 4] [5 6 7 8 9] [10 11 12 13 14] [15 16 17 18 19] [20 21 22 23 24]]