numpy数组的argmax返回非固定索引 [英] Argmax of numpy array returning non-flat indices
问题描述
我正在尝试获取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.argmax
与axis=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?
推荐答案
您可以使用 查看全文