正如问题所示,是否有一种有效的方法可以在矩阵的每行/每列中找到最常出现的数字?
我尝试了以下但是不起作用:
r = numpy.zeros(shape = (2,3))
r[0][0] = 1
r[0][1] = 1
'''
now the matrix looks like:
[[ 1., 1., 0.],
[ 0., 0., 0.]]
'''
numpy.argmax(numpy.bincount(r))
我希望它返回这样的内容:
[1, 0] # 1 is the most frequent number in 1st row, and 0 for the 2nd row
当我打电话时,我收到以下错误:
ValueError: object too deep for desired array
我做错了什么?