Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_lower_resolution(elevation_map: List[List[int]]) -> List[List[int]]:
- '''Return a new elevation map, which is constructed from the values
- of elevation_map by decreasing the number of points within it.
- Precondition: elevation_map is a valid elevation map.
- >>> get_lower_resolution(
- ... [[1, 6, 5, 6],
- ... [2, 5, 6, 8],
- ... [7, 2, 8, 1],
- ... [4, 4, 7, 3]])
- [[3, 6], [4, 4]]
- >>> get_lower_resolution(
- ... [[7, 9, 1],
- ... [4, 2, 1],
- ... [3, 2, 3]])
- [[5, 1], [2, 3]]
- '''
- newmap = []
- m = elevation_map
- for i in range(0, len(elevation_map)-1, 2):
- newmap.append([])
- for j in range(0, len(elevation_map[i]), 2):
- if len(elevation_map) % 2 == 0:
- s = m[i][j]
- s += m[i][j+1]
- s += +m[i+1][j]
- s += m[i+1][j+1]
- newmap[-1].append(int(s/4))
- else:
- s = elevation_map[i][j]
- s += elevation_map[i+1][j]
- newmap[-1].append(int(s/2))
- if in_matrix(elevation_map,[i,j+1]):
- return newmap
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement