classSolution: defimageSmoother(self, img: List[List[int]]) -> List[List[int]]: m, n = len(img), len(img[0]) ans = [[0for _ inrange(n)] for _ inrange(m)] directions = [-1, 0, 1] for i inrange(m): for j inrange(n): count = 0 total = 0 for row in directions: for col in directions: if0 <= i+row <= m-1and0 <= j+col <= n-1: total += img[i+row][j+col] count += 1 average = total // count ans[i][j] = average return ans