我有一个numpy数组,除了第一个轴外,我想对所有的轴进行讨论。我有(我认为)一个解决办法,但我不知道是否有更好的办法。import numpy as np
## Argmax along all axes except the first (ie axis 0), axis=last_axis) argmax_smaller_a
我想在dataframe的列中找到子字符串的第一次出现。我想要一种简洁的方法来做这件事,所以我尝试使用argmax。单元格是设置好的,所以“快乐”是这个搜索的一个合适的子字符串。我现在的工作是:
# For-loop that gets me the row in which a happy mood type occurs'Happy' in
基本上,我想对任意维的Numpy数组进行以下Python等效,并指定一个任意轴:也就是说,根据最大绝对值选择元素(类似于array.max(axis=axis)dims = list(a.shape) indices = np.ogrid[tuple(slice(0, d) for d in dims)] indices.insert((len(a.