julia - Julia using argmax to return index within a row of a matrix instead of a CartesianIndex
问题描述
Say I have a matrix
X = [1 2 3 4; 1 4 3 2];
I would like to find the argmax of each row of this matrix, relative to that row and not the index of the entry within the entirety of X. Meaning that I want the output of argmax(X, dims = (2)) to be a vector,
[4, 2];
but the current output is an array of CartesianIndex
[CartesianIndex(1, 4), CartesianIndex(2, 2)];
Is there a way to specify this in the argmax function or to transform the output efficiently to my desired state?
解决方案
您可以使用eachrow
迭代矩阵的行:
julia> argmax.(eachrow(X))
2-element Vector{Int64}:
4
2
推荐阅读
- python - Tweepy API:为附加的照片添加标签/提及
- azure - 有没有办法在 azure b2c 的登录页面中添加自定义字段?
- javascript - 如何遍历 javascript 中的内容数据并在引导网格列中显示?
- google-apps-script - 如何编辑脚本以通过邮件发送表格谷歌表?
- java - Java if/else、while 和用户输入
- java - 从 Logback 和 Spring Boot 中的 application-properties 文件加载 datePattern
- c# - 获取请求的地址在其上下文中无效。在我的聊天应用程序中
- javascript - 在 Vue.js 中动态访问嵌套数组时,push 不是函数
- c# - Select2 PlugIn 所选值未更新为 DropDownList
- jquery - 如何将外部 js 文件添加到 vue cli 应用程序中?