
在二维网格化化平面找位置,可以用网格化二元插值法法吗?应该怎样做?
import numpy as np
# create matrix with altitude values
matrix = np.array([[1, 3, 5], [2, 4, 6], [7, 8, 9]])
# create empty dictionary to store peaks, valleys, and canyons
results = {'peak': [], 'valley': [], 'canyon': []}
# find index of minimum and maximum values in matrix
min_row, min_col = np.unravel_index(matrix.argmin(), matrix.shape)
max_row, max_col = np.unravel_index(matrix.argmax(), matrix.shape)
# iterate over each position in matrix and compare to neighboring positions
for i in range(matrix.shape[0]):
for j in range(matrix.shape[1]):
if i > 0 and i < matrix.shape[0]-1 and j > 0 and j < matrix.shape[1]-1:
if matrix[i,j] > matrix[i-1,j] and matrix[i,j] > matrix[i+1,j] and matrix[i,j] > matrix[i,j-1] and matrix[i,j] > matrix[i,j+1]:
results['peak'].append((i,j))
elif matrix[i,j] < matrix[i-1,j] and matrix[i,j] < matrix[i+1,j] and matrix[i,j] < matrix[i,j-1] and matrix[i,j] < matrix[i,j+1]:
results['valley'].append((i,j))
elif matrix[i,j] > matrix[i-1,j] and matrix[i,j] < matrix[i+1,j] and matrix[i,j] < matrix[i,j-1] and matrix[i,j] < matrix[i,j+1]:
results['canyon'].append((i,j))
print('Peaks:', results['peak'])
print('Valleys:', results['valley'])
print('Canyons:', results['canyon'])