numpy - 是否有numpy.argmax的Julia类似物?

标签 numpy julia argmax

在Python中,存在numpy.argmax:

In [7]: a = np.random.rand(5,3)

In [8]: a
Out[8]: 
array([[ 0.00108039,  0.16885304,  0.18129883],
       [ 0.42661574,  0.78217538,  0.43942868],
       [ 0.34321459,  0.53835544,  0.72364813],
       [ 0.97914267,  0.40773394,  0.36358753],
       [ 0.59639274,  0.67640815,  0.28126232]])

In [10]: np.argmax(a,axis=1)
Out[10]: array([2, 1, 2, 0, 1])

是否有Numpy的argmax的Julia类似物?我只找到了indmax,它只接受一个向量,而不是np.argmax的二维数组。

最佳答案

最快的实现通常是findmax(如果需要,您可以一次缩小多个维度):

julia> a = rand(5, 3)
5×3 Array{Float64,2}:
 0.867952  0.815068   0.324292
 0.44118   0.977383   0.564194
 0.63132   0.0351254  0.444277
 0.597816  0.555836   0.32167 
 0.468644  0.336954   0.893425

julia> mxval, mxindx = findmax(a; dims=2)
([0.8679518267243425; 0.9773828942695064; … ; 0.5978162823947759; 0.8934254589671011], CartesianIndex{2}[CartesianIndex(1, 1); CartesianIndex(2, 2); … ; CartesianIndex(4, 1); CartesianIndex(5, 3)])

julia> mxindx
5×1 Array{CartesianIndex{2},2}:
 CartesianIndex(1, 1)
 CartesianIndex(2, 2)
 CartesianIndex(3, 1)
 CartesianIndex(4, 1)
 CartesianIndex(5, 3)

关于numpy - 是否有numpy.argmax的Julia类似物?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34759011/

相关文章:

python - numpy python中的"AttributeError: '矩阵' object has no attribute '等历'"

python - 绘制散点图最密集区域的等高线

python - 如何从 Python 的邻接表中选择一个子矩阵?

python - 我可以在 np.mean() 中使用 str 吗?

julia - 如何设置 Plots 的默认属性?

ascii - 在 Julia 中,如何将 ASCII 十进制列表转换为字符串?

arguments - Julia:将多个参数传递给匿名函数

Tensorflow Argmax : What's the difference between "axis" and "dimension" parameter?

python - 3 维 ndarray 的最后一个维度上的棘手 numpy argmax

Python - 直方图上的argmax