WHERE简介
按照指定条件查找数组元素,并返回数组中满足条件的元素的下标。
语法:
result=where(array_expression [,count] [,complement=variable],[,ncomplement=variable] )
array_expression :数组表达式
count:符合条件的元素个数(换成其他字符串也可)
complement:不满足条件的元素下标
ncomplement:不满足条件的元素个数
例子
a=[1,2,3,4,5]
b=where(a gt 3,count)
print,b
print,count
print,a[b]
end
3 4 符合条件的元素下标(一维)
2 符合条件的元素个数
4 5
其中:
gt:>;
eq:=;
ne:≠
ge:>=
le:<=
lt:<
不区分大小写
2.
a=[1,2,3,4,5]
b=where(a gt 3 and a le 5,count)
print,b
print,count
print,a[b]
end
3 4
2
4 5
注意:
where函数返回的下标始终是一维的(IDL中任何数组都可看作是一维),若想知道具体行列号要做转化。—利用array_indices函数
s=[[1,2,3],[4,5,6],[7,8,9]]
q=where(s gt 4)
print,q
print,array_indices(s,q)
end
4 5 6 7 8
1 1
2 1
0 2
1 2
2 2
列号 行号
注意:IDL先输出列号再输出行号