IDL where函数与array_indices函数

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先输出列号再输出行号

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值