numpy数组的argmax返回非固定索引 [英] Argmax of numpy array returning non-flat indices

查看:152
本文介绍了numpy数组的argmax返回非固定索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取Numpy数组中最大元素的索引. 可以使用numpy.argmax完成.我的问题是,我想在整个数组中找到最大的元素并获取其索引.

I'm trying to get the indices of the maximum element in a Numpy array. This can be done using numpy.argmax. My problem is, that I would like to find the biggest element in the whole array and get the indices of that.

numpy.argmax既可以沿一个轴而不是我想要的方向应用,也可以沿扁平数组应用,这正是我想要的.

numpy.argmax can be either applied along one axis, which is not what I want, or on the flattened array, which is kind of what I want.

我的问题是,当我想要多维索引时,将numpy.argmaxaxis=None一起使用会返回平面索引.

My problem is that using numpy.argmax with axis=None returns the flat index when I want the multi-dimensional index.

我可以使用divmod来获取非固定索引,但这很难看.有什么更好的方法吗?

I could use divmod to get a non-flat index but this feels ugly. Is there any better way of doing this?

推荐答案

您可以使用 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆