如何在Python中获取numpy数组每行最大值的索引?
获取numpy数组每行最大值的索引
要获取数组每行最大值对应的索引,直接使用numpy的argmax()函数并指定axis=1参数即可,该参数表示沿行方向计算最大值的索引。
完整代码示例:
import numpy as np Pr = np.array([[1.72731864e+003, 0.00000000e+000], [0.00000000e+000, 1.24439020e+003]]) # 获取每行最大值的索引 indices = Pr.argmax(axis=1) print(f"indices={indices.tolist()}")
运行后输出:
indices=[0, 1]
内容的提问来源于stack exchange,提问作者isaacmodi123
相关产品推荐
相关产品推荐

