Go solution using range, append and mod
go\nfunc matrixReshape(mat [][]int, r int, c int) [][]int {\n\tif len(mat) == 0 || len(mat[0]) == 0 {\n\t\treturn mat\n\t} else if r*c != len(mat)*len(mat[0]) {
```go\nfunc matrixReshape(mat [][]int, r int, c int) [][]int {\n\tif len(mat) == 0 || len(mat[0]) == 0 {\n\t\treturn mat\n\t} else if r*c != len(mat)*len(mat[0]) {\n\t\treturn mat\n\t}\n\n\tresult := [][]int{}\n\tp := 0\n\n\tfor _, row := range mat {\n\t\tfor _, v := range row {\n\t\t\tif p%c == 0 {\n\t\t\t\tresult = append(result, []int{v})\n\t\t\t} else {\n\t\t\t\tresult[p/c] = append(result[p/c], v)\n\t\t\t}\n\n\t\t\tp++\n\t\t}\n\t}\n\n\treturn result\n}\n```
['Go']