Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在2d numpy数组中查找满足条件的值的索引_Python_Arrays_Numpy - Fatal编程技术网

Python 在2d numpy数组中查找满足条件的值的索引

Python 在2d numpy数组中查找满足条件的值的索引,python,arrays,numpy,Python,Arrays,Numpy,我有一个2D的值数组,我想找到值超过最大值60%的索引。我试过: : nmax, nmin = np.amax((n[:,:])),np.amin((n[:,:])) : np.unravel_index(n[n>0.6*nmax], n.shape) 但我得到了一个错误: TypeError: Iterator operand 0 dtype could not be cast from dtype('>f4') to dtype('int64') according to th

我有一个2D的值数组,我想找到值超过最大值60%的索引。我试过:

: nmax, nmin = np.amax((n[:,:])),np.amin((n[:,:]))
: np.unravel_index(n[n>0.6*nmax], n.shape)
但我得到了一个错误:

TypeError: Iterator operand 0 dtype could not be cast from dtype('>f4') to dtype('int64') according to the rule 'same_kind'

如有任何见解,将不胜感激

如上所述,使用np。其中:

    x = np.random.randint(0,50,(20,20))
    y = np.where(x>0.6*np.max(x))
y将作为一个元组给出,其中两个数组表示数组的两个轴,您可以使用y,但是您需要使用y。例如,x[y]将返回x的值,所有这些值都将大于0.6*最大值。

您尝试过吗?