To create a D slice dynamically, allocate each row separately:
rows := 3
cols := 4
matrix := make([][]int, rows)
for i := range matrix {
matrix[i] = make([]int, cols)
}
This creates a by matrix initialized to zeros. Each row is its own slice with independent memory. The outer slice holds pointers to these row slices.