Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others


0 votes
in Technique[技术] by (71.8m points)

python - Find Nearest Transition in N-dimensional Array

I want to find index of the nearest transition in a numpy ndarray of integers given a current index in an efficient manner. Transition means a change of value.

For example, in the 2D array below, the right output for location (2,4) would be (3,6) (transition from Class 1 to Class 8) at the approximate distance of 2.236. In case of more than one optimum, returning any would suffice.

import seaborn as sns
import numpy as np

step_size = [1,1]  # size of step in each dimension
arr = np.array([[6,6,1,1,1,1,1,1,1,8],[6,1,1,1,1,1,1,1,8,8],[6,1,1,1,1,1,1,1,8,8],[6,1,1,1,1,1,8,8,8,8],[6,6,1,1,1,1,1,8,8,8]])
sns.heatmap(arr, annot=True, cbar=False)

enter image description here

The application is to estimate distances to boundaries. Such as a sample's distance to decision boundary in classification algorithms where an accurate algorithm or formula for that is not available (like xgboost, and unlike SVM and decision trees).

See Question&Answers more detail:os

Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share