【发布时间】:2014-05-05 19:01:06
【问题描述】:
在 R 中,这段代码可以正常工作:
denom <- matrix(c(0.1125588, 2.1722226, 0.5424582, 1.1727604,3.0524269 ,0.0524625 ,0.1752363 ,0.7198743,0.7282291 ,0.1646349 ,0.7574503, 2.3496857),3,4,byrow=TRUE)
indexM <- apply(denom,1,function(x) which(x==max(x)))
indexM
# 2 1 4
这是否接近 Python 等价物?它不起作用(AttributeError: 'tuple' object has no attribute 'ndim')
denom = np.array([[0.1125588, 2.1722226, 0.5424582], [1.1727604,3.0524269 ,0.0524625] ,[0.1752363 ,0.7198743,0.7282291] ,[0.1646349 ,0.7574503, 2.3496857]]);
indexM = np.apply_over_axes(lambda x,y: np.where(x == x.max(axis=1)) ,denom, axes=(0) );
【问题讨论】: