简体   繁体   English

我不明白为什么 np.argwhere 没有为我的第一行返回一些东西

[英]I don't understand why np.argwhere doesn't return something for my first row

I have an array, and I want to find where are the max value for each row.我有一个数组,我想找到每一行的最大值在哪里。 On the same row I can have the two values that are the maximum, so I decided to use np.argwhere.在同一行我可以有两个最大值,所以我决定使用 np.argwhere。

np.argwhere(a == np.amax(a,axis=1))

but for my first row, it output nothing and I don't understand why.但是对于我的第一行,它什么都不输出,我不明白为什么。

np.amax returns a row array, while you want a column one. np.amax返回一个行数组,而你想要一个列。 Hence, you want to reshape your array before performing the computation:因此,您想在执行计算之前重塑数组:

np.argwhere(a == np.amax(a, axis=1).reshape((-1,1)))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM