IDL uniq函数返回右相邻不同值的该值索引

如果数组中从左往右遍历,某索引处的该值不等于右相邻值的话,则返回该值对应的在原始数组中的索引,例如

array = [1, 2, 1, 2, 3, 4, 5, 6, 6, 5]
IDL> uniq(array)
0 1 2 3 4 5 6 8 9

IDL> b = sort(array)
IDL> print,b
2 0 3 1 4 5 9 6 8 7

IDL> uniq(array,b)
0 1 4 5 6 7
指定参数b的话,就是对升序后的数组进行查找右相邻不同数值的索引,如果右侧相邻数值不同于该值,则将该值索引返回,此处该值索引是sort()的返回值,即b数组的对应值。

加sort返回值的话,则是返回从小到大排列后的数组的该值不同于右相邻值时该值在sort中的值做为自己的索引。

IDL官方解释

UNIQ
The UNIQ function returns the subscripts of the unique elements in an array. Note that repeated elements must be adjacent in order to be found. This routine is intended to be used with the SORT function: see the examples below. This function was inspired by the UNIX uniq(1) command.

This routine is written in the IDL language. Its source code can be found in the file uniq.pro in the lib subdirectory of the IDL distribution.

Examples
Find the unique elements of an unsorted array:

; Create an array:
array = [1, 2, 1, 2, 3, 4, 5, 6, 6, 5]

; Variable B holds an array containing the sorted,
; unique values in array:
b = array[UNIQ(array, SORT(array))]
PRINT, b

IDL prints

1 2 3 4 5 6

Syntax
Result = UNIQ( Array [, Index] )

Return Value
UNIQ returns an array of indices into the original array. Note that the index of the last element in each set of non-unique elements is returned. If the optional Index argument is supplied, then the last index in the order provided by the Index array is returned.

The following expression returns a copy of the sorted array with duplicate adjacent elements removed:

Array[UNIQ(Array)]

UNIQ returns 0 (zero) if the argument supplied is a scalar rather than an array.

Arguments
Array
The array to be scanned. For UNIQ to work properly, the array must be sorted into monotonic order unless the optional parameter Index is supplied.

Index
This optional parameter is an array of indices into Array that order the elements into monotonic order. That is, the expression:

Array[Index]

yields an array in which the elements of Array are rearranged into monotonic order.

The Index array can be generated from Array using the SORT function:

Index = SORT(Array)

If Array is not already in monotonic order, use the command:

UNIQ(Array, SORT(Array))


与其热闹的引人夺目,步步紧逼,不如逐向做一个人群之中真实自信的人,不张扬,不虚饰,随时保持后退的位,心有所定,只是专注做事。——素年锦时

版权归作者 小白是哪个小白_ 所有,转载、引用请注明链接出处。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值