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

时间:2015-03-26 00:49:56

标签: python arrays numpy

我有一个二维值数组,我想找到值超过最大值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'

任何见解都将受到赞赏。

1 个答案:

答案 0 :(得分:0)

如上所述,使用像这样的np.where():

    x = np.random.randint(0,50,(20,20))
    y = np.where(x>0.6*np.max(x))

y将作为一个元组给出,其中两个数组代表数组的两个轴,你可以使用y但是你需要例如x [y]将返回x的值,所有这些都将大于0.6 *最大

相关问题