- 对
Go
的多维切片的初始化语法不是特别熟悉 - 还有一种 [[算法-前缀和]] ,但是是二维数组的前缀和,没有深究
func imageSmoother(img [][]int) [][]int {
ret := make([][]int, len(img))
for i, v := range img {
ret[i] = make([]int, len(v))
// fmt.Println(i)
for j, _ := range v {
sum, num := 0, 0
for k := i-1; k <= i+1; k++ {
// fmt.Println(k)
for l := j-1; l <= j+1; l++ {
// fmt.Println(l)
if l >= 0 && l < len(v) && k >= 0 && k < len(img) {
sum += img[k][l]
num++
}
}
}
// fmt.Println(i,j)
ret[i][j] = sum/num
}
}
return ret
}