美文网首页
[Python] 寻找一个ndarray中最接近某个值的点ind

[Python] 寻找一个ndarray中最接近某个值的点ind

作者: Ytlu | 来源:发表于2021-10-09 14:18 被阅读0次

find_nearest

找到ndarray中最接近给定值的那个点的index。
类似于ncl中的ind_nearest_recoord

import numpy as np
def find_nearest(array, value):
    '''
    Get the index of the nearest value in an array
    '''
    array = np.asarray(array)
    idx = (np.abs(array - value)).argmin()
    return idx

相关文章

网友评论

      本文标题:[Python] 寻找一个ndarray中最接近某个值的点ind

      本文链接:https://www.haomeiwen.com/subject/ipeqoltx.html