1.where的基本用法
函數WHERE()能返回數組中滿足指定條件的元素下標
調用格式:
Result=Where(數組表達式[,count][,Complement=變量1][,/L64][,NCOMPLEMENT=變量2])
其中,關鍵字count返回符合指定條件的元素個數;變量1為不滿足條件的數組元素下標;變量2為不滿足條件的數組元素個數
eg:
IDL> a=[[1,2],[3,4]]
IDL> print,a
1 2
3 4
IDL> c=where(a ge 2, count)
IDL> print,count ;count:對應於a中大於等於2的元素個數
3
2.使用where返回對應數值的二維坐標
result 返回的是一維的坐標
要想返回二維坐標,需要使用array_indices函數
eg:
a=[[1,2],[3,4]]
IDL> print,a
1 2
3 4
IDL> pos=where(a eq 3)
IDL> print,pos
2
IDL> qc_dims=size(a,/dimensions)
IDL> pos2=array_indices(qc_dims,pos,/dimensions) ;pos2對應於值為3的二維坐標
IDL> print,pos2
0 1
IDL> print,a[pos2[0],pos2[1]]
3
備注:學習的相關內容是從鏈接:https://www.cnblogs.com/wintertone/p/6596672.html 摘出來的,為了方便整理就寫在自己的博客園中。