| 查看: 490 | 回复: 2 | |||
| 当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖 | |||
wxyuan2014铜虫 (小有名气)
|
[求助]
求一维数组最小值索引 已有2人参与
|
||
| 大家好,请问Java中有没有求数组最小值索引的函数呢,类似的在MATLAB中有w=find(n==min(n(0:99))) |
» 猜你喜欢
一个化合物的合成路线:CAS:367929-02-0 名称:8β-乙烯基雌二醇
已经有4人回复
太白金星有点烦
已经有3人回复
中国地质大学(北京)博士招生补录,数理学院材料科学与工程专业和材料与化工专业
已经有3人回复
河北省自然基金
已经有8人回复
收到国自然专家邀请后几年才会有本子送过来评
已经有3人回复
考博
已经有3人回复
有没有快的中文核心比较快录用的,纳米材料光催化
已经有4人回复
本人42,博士刚毕业,现在找不到工作,怎么办?:(
已经有21人回复
有人投过CCC中国控制会议吗?
已经有3人回复
3,4-二羟基苯乙酮如何纯化?
已经有5人回复

jianliu67
木虫 (小有名气)
- 应助: 27 (小学生)
- 金币: 4053.5
- 红花: 4
- 帖子: 216
- 在线: 135.7小时
- 虫号: 3511817
- 注册: 2014-11-01
- 性别: GG
- 专业: 计算机科学的基础理论
【答案】应助回帖
★ ★ ★ ★ ★
感谢参与,应助指数 +1
wxyuan2014: 金币+5 2016-08-09 15:54:08
感谢参与,应助指数 +1
wxyuan2014: 金币+5 2016-08-09 15:54:08
|
看你追求什么了. 1. 如果追求效率, 你得自己写一段code, 循环整个数组, 得到最小值的同时保存它的index. 2. 如果只追求代码简洁好看, 可以这样写: int minIndex = list.indexOf(Collections.min(list)), 这里 <ArrayList>list 是你的数组. The second one is exactly like the Matlab method you wanted, but it goes through the same list twice in the worst case scenario. The first method only goes through the list once so it's faster. |
3楼2016-08-09 10:40:45
FMStation
至尊木虫 (知名作家)
- 应助: 591 (博士)
- 贵宾: 0.03
- 金币: 18701.7
- 红花: 97
- 帖子: 8891
- 在线: 1493.2小时
- 虫号: 2400059
- 注册: 2013-04-04
- 专业: 计算机应用技术
【答案】应助回帖
★ ★ ★ ★ ★
感谢参与,应助指数 +1
wxyuan2014: 金币+5 2016-08-08 15:43:13
感谢参与,应助指数 +1
wxyuan2014: 金币+5 2016-08-08 15:43:13
|
C Code: #include<stdio.h> int main(void) { int i, j, size_A=2, size_A2=3; float A[2][3]= {{-1e300, 2, 3},{2,-1e300,5}}; /*NOTE: -1e300 outputs as -Inf*/ int size_index=0; int rloc, cloc; float index[size_A*size_A2]; for(j=0; j<size_A2; j++) /*Finds rows where values in each column are greater than -Inf. Also finds length of new linear matrix*/ { for(i=0; i<size_A; i++) { if(A[j]>-1e300) { cloc=j+1; rloc=i+1; size_index++; index[1][size_index]= rloc; printf("col:%d\nrow:%d\nsize:%d\n", cloc, rloc, size_index); }printf("%d", index[1][size_index]); } } return 0; } http://cboard.cprogramming.com/c ... -find-function.html |
2楼2016-08-08 14:16:42












回复此楼