您的位置:首页 > 其它

唤起那些年你对IDL的记忆(一)

2016-08-05 17:19 316 查看
仅做复习参考用:本文整理参考了IDL-Help跟董彦卿老师编写的教材

基础

常用的命令及快捷键

输出:print

查看:help

续行符:$

同行符:&

注释符: ;

常用快捷键:



图1 快捷键

语法

数据类型

IDL有17中基本数据类型,如下图所示:



图2 数据类型

Size (源:IDL-help)

**description:**The SIZE function returns size and type information for its argument if no keywords are set. If a keyword is set, SIZE returns the specified quantity.

Examples

Print the size information for a 10 by 20 floating-point array by entering:

PRINT, SIZE(FINDGEN(10, 20))

IDL prints:

2 10 20 4 200 (1、维数 2、各位数的大小 3、类型Code 4、元素数)

This IDL output indicates the array has 2 dimensions, equal to 10 and 20, a type code of 4, and 200 elements total. Similarly, to print only the number of dimensions of the same array:

PRINT, SIZE(FINDGEN(10, 20), /N_DIMENSIONS)

IDL prints:

2

For more information on using SIZE, see the Additional Examples.

Syntax

Result = SIZE( Expression [, /L64] [, /DIMENSIONS | , /FILE_LUN | , /FILE_OFFSET | , /N_DIMENSIONS | , /N_ELEMENTS | , /SNAME, | , /STRUCTURE | , /TNAME | , /TYPE] )

Return Value

If no keywords are set, SIZE returns a vector of integer type. The first element is equal to the number of dimensions of Expression. This value is zero if Expression is scalar or undefined. The next elements contain the size of each dimension, one element per dimension (none if Expression is scalar or undefined). After the dimension sizes, the last two elements contain the type code (zero if undefined) and the number of elements in Expression, respectively. The type codes are listed below.

If a keyword is set, SIZE returns the specified information.

Note: The SIZE function treats lists and hashes as if they are one-dimensional arrays.

IDL Type Codes and Names

The following table lists the IDL type codes and type names returned by the SIZE function:



图3 Type Codes and Names

变量与常量

变量分为:局部变量和系统变量

1、命名规则

变量长度:不能超过255个字符

首位:字母或下划线

中后部:字母、下划线、$

2、IDL_Validname (源:IDL-Help)

检查变量名

The IDL_VALIDNAME function determines whether a string may be used as a valid IDL variable name or structure tag name. Optionally, the routine can convert non-valid characters into underscores, returning a valid name string.

Example



图4 IDL_Validaname

CONVERT_ALL

If this keyword is set, then each element of String is converted into a valid IDL variable name using the following rules:

All non-alphanumeric characters (except “_”, “!” and “$”) are converted to underscores

If the first character is a number or a “$”,then an underscore is prepended to the string

If the first character is not a valid character (“_”, “!”, “A”…“Z”) then that character is converted to an underscore

If the element of String is an empty string or a reserved word (such as “AND”) then an underscore is prepended to the string

Tip: The CONVERT_ALL keyword guarantees that a valid variable name is returned. It is useful in converting user-supplied strings into valid IDL variable names.

CONVERT_SPACES

If this keyword is set, then all spaces within each element of String are converted to underscores. If an element of String contains any other non-alphanumeric characters, then an empty string is returned, indicating that the string cannot be used as a valid variable name.

Note: CONVERT_SPACES behaves the same as CREATE_STRUCT when checking structure tag

3、N_Elements函数

判断变量是否已经被定义,如果定义返回1,否则返回0.

4、类型转换



图5 类型转换函数

5、改变数组部分元素不改变数组数据类型

6、系统变量

分为预定义系统变量和自定义系统变量

预定义系统变量:常数变量、图形变量、系统配置、错误处理



图6 常数变量



图7 图像变量





图8 系统配置



图9 错误处理

自定义系统变量格式:Defsysv,变量名,变量值

注:自定义系统变量创建成功后,只可以修改,但是类型不变,生命周期从初始化成功到IDL进程关闭。

数组

数组是IDL中最重要的数据组织形式,支持0~8维,下标顺序先列标、后行标。

1、数组创建函数



图10 数组创建函数

2、创建特定类型或数值的数组

MAKE_ARRAY

The MAKE_ARRAY function enables you to dynamically create an array whose characteristics are not known until run time.

Examples

To create a 3-element by 4-element integer array with each element set to the value 5, enter:

M = MAKE_ARRAY(3, 4, /INTEGER, VALUE = 5)

Syntax

Result = MAKE_ARRAY ( [D1[, …, D8]] [, DIMENSION=vector] [, INCREMENT=value] [, /INDEX] [, /NOZERO] [, SIZE=vector] [, START=value] [, TYPE=type_code] [, VALUE=value] [, /BYTE | , /COMPLEX | , /DCOMPLEX | , /DOUBLE | , /FLOAT | , /INTEGER | , /L64 | , /LONG | , /OBJ, | , /PTR | , /STRING | , /UINT | , /UL64 | , /ULONG] )

3、存储数组

按行存储

4、使用数组

@1、下标方式

IDL> arr=indgen(8)
IDL> print,arr
0       1       2       3       4       5       6       7
IDL> print,arr[4]
4


注:8.0之后下标可以为负,-1代表最后一个元素。*

IDL> print,arr[-1]
7
IDL> print,arr[-5:-1]
3       4       5       6       7


@2、向量方式

读取第1、2、4、5元素值

IDL> print,arr
0       1       2       3       4       5       6       7
IDL> index=[0,1,3,4]
IDL> result=arr[index]
IDL> print,result
0       1       3       4


5、数组运算

@1、求大求小和求余

注:求大、求小时会将数组不符合的元素全都改变成比较的数值

IDL> print,arr
0       1       2       3       4       5       6       7
IDL> print,arr>4
4       4       4       4       4       5       6       7
IDL> print,arr<6
0       1       2       3       4       5       6       6
IDL> print,arr mod 3
0       1       2       0       1       2       0       1


@2、数组与数的运算

每个元素与数进行运算

IDL> print,arr
0       1       2       3       4       5       6       7
IDL> result=arr*2
IDL> print,result
0       2       4       6       8      10      12      14
IDL> print,arr+3
3       4       5       6       7       8       9      10


@3、数组与数组运算

结果元素个数与参与运算数组最少元素个数的数组一致,数组元素运算按照行优先顺序依次进行运算。

IDL> arr1=indgen(3,2)
IDL> print,arr1
0       1       2
3       4       5
IDL> arr2=indgen(3,2)*2
IDL> print,arr2
0       2       4
6       8      10
IDL> arr3=indgen(2,3)
IDL> print,arr3
0       1
2       3
4       5
IDL> result=arr1+arr2
IDL> print,result
0       3       6
9      12      15
IDL> print,arr1+arr3
0       2       4
6       8      10
IDL> arr4=indgen(4)
IDL> print,arr1+arr4
0       2       4       6


@4、数组合并

数组合并要求:两个数组行数或者列数相同。

注:列数相同合并写法方式

行数相同:
IDL> print,arr1
0       1       2
3       4       5
IDL> print,arr4
0       1       2       3
IDL> arr5=[arr1,arr4]
% Unable to concatenate variables because the dimensions do not agree: ARR4.
% Execution halted at: FIRST               4 F:\学习资料\IDL\code\Default\first.pro
%                      $MAIN$
IDL> arr6=indgen(4,2)*3
IDL> print,arr6
0       3       6       9
12      15      18      21
IDL> arry5=[arr1,arr6]
IDL> print,arry5
0       1       2       0       3       6       9
3       4       5      12      15      18      21
列数相同:
IDL> print,arr1
0       1       2
3       4       5
IDL> print,arr7
0       1       2
3       4       5
6       7       8
9      10      11
IDL> result=[arr1,arr7]
% Unable to concatenate variables because the dimensions do not agree: ARR7.
% Execution halted at: FIRST               4 F:\学习资料\IDL\code\Default\first.pro
%                      $MAIN$
IDL> result=[[arr1,arr7]]
% Unable to concatenate variables because the dimensions do not agree: ARR7.
% Execution halted at: FIRST               4 F:\学习资料\IDL\code\Default\first.pro
%                      $MAIN$
IDL> result=[[arr1],[arr7]]
IDL> print,result
0       1       2
3       4       5
0       1       2
3       4       5
6       7       8
9      10      11


6、数组相关函数

@1、条件查询–WHERE(源IDL-Help)

The WHERE function returns a vector that contains the one-dimensional subscripts of the nonzero elements of Array_Expression. The length of the resulting vector is equal to the number of nonzero elements in Array_Expression. Frequently the result of WHERE is used as a vector subscript to select elements of an array using given criteria.

Note: When WHERE Returns –1

If the NULL keyword is not set, and all the elements of Array_Expression are zero, then WHERE returns a scalar integer with a value of –1. If you use this result as an index into another array without checking for –1 first, then this will return the last element of the array. To avoid this problem, you should either use /NULL or check the Count argument before indexing. For example:

; Use /NULL, if no elements match then array will not be modified:

array[WHERE(array GT 5, /NULL)] = 5

or,

; Use Count to get the number of nonzero elements:

index = WHERE(array GT 5, count)

; Only subscript the array if it is safe:

IF count NE 0 THEN array[index] = 5

Syntax

Result = WHERE( Array_Expression [, Count] [, COMPLEMENT=variable] [, /L64] [, NCOMPLEMENT=variable] [, /NULL] )

IDL> print,arr
0       1       2       3       4       5       6       7
IDL> result=where(arr gt 3)
IDL> result1=where(arr lt 4)
IDL> result2=where(arr eq 5)
IDL> result3=where(arr ge 3)
IDL> result4=where(arr le 6)
IDL> print,result,result1,result2,result3,result4
4           5           6           7
0           1           2           3
5
3           4           5           6           7
0           1           2           3           4           5           6


@2、调整大小–Reform()、Rebin()、Congrid()、Interpolate()函数

#1、Reform()

The REFORM function changes the dimensions of an array without changing the total number of elements.

修改维数,数组元素大小不变

Examples

REFORM can be used to remove “degenerate” leading dimensions of size one. Such dimensions can appear when a subarray is extracted from an array with more dimensions. For example

; a is a 3-dimensional array:

a = INTARR(10,10,10)

; Extract a "slice" from a:
b = a[5,*,*]

; Use HELP to show what REFORM does:
HELP, b, REFORM(b)
Executing the above statements produces the output:
B            INT = Array[1, 10, 10]
<Expression> INT = Array[10, 10]


The statements have the identical effect. They create a new array, b, with dimensions of (200, 5), from a.:

b = REFORM(a,200,5)
b = REFORM(a,[200,5])


Syntax

Result = REFORM( Array, D1[, …, D8] [, /OVERWRITE] )

OVERWRITE:

Set this keyword to cause the specified dimensions to overwrite the present dimensions of the Array parameter. No data are copied, only the internal array descriptor is changed. The result of the function, in this case, is the Array parameter with its newly-modified dimensions. For example, to change the dimensions of the variable a, without moving data, enter:

a = REFORM(a, n1, n2, /OVERWRITE)

#2、Rebin()

The REBIN function resizes a vector or array to dimensions given by the parameters Di. The supplied dimensions must be integral multiples or factors of the original dimension. The expansion or compression of each dimension is independent of the others, so that each dimension can be expanded or compressed by a different value.

If the dimensions of the desired result are not integer multiples of the original dimensions, use the CONGRID function.

修改数组大小,修改后数组行或列数必须是原数组行列数的整数倍,默认抽样算法是双线性内插

IDL> print,arr2
0       2       4
6       8      10
IDL> result=rebin(arr2,6,4)
IDL> print,result
0       1       2       3       4       4
3       4       5       6       7       7
6       7       8       9      10      10
6       7       8       9      10      10
IDL> result=rebin(arr2,6,4,/sample)
IDL>;sample:最近邻抽样算法
IDL> print,result
0       0       2       2       4       4
0       0       2       2       4       4
6       6       8       8      10      10
6       6       8       8      10      10


#3、Congrid()

The CONGRID function shrinks or expands the size of an array by an arbitrary amount. CONGRID is similar to REBIN in that it can resize a one, two, or three dimensional array, but where REBIN requires that the new array size must be an integer multiple of the original size, CONGRID will resize an array to any arbitrary size. (REBIN is somewhat faster, however.) REBIN averages multiple points when shrinking an array, while CONGRID just resamples the array.

**可以将数组调整为同维任意大小。

处理一维、二维数组时,默认算法是最近邻重采样;

处理三维数组时,默认采用双线性内插算法;

在对数组进行缩小操作时,采用Rebin()函数进行插值处理,Congrid()函数仅进行重采样。

Syntax

Result = CONGRID( Array, X, Y, Z [, /CENTER] [, CUBIC=value{-1 to 0}] [, /INTERP] [, /MINUS_ONE] )

IDL>;默认采用最近邻重采样算法
IDL> print,arr2
0       2       4
6       8      10
IDL> print,congrid(arr2,4,5)
0       2       4       4
0       2       4       4
0       2       4       4
6       8      10      10
6       8      10      10


#4、Interpolate()

The INTERPOLATE function returns an array of linear, bilinear or trilinear interpolates, depending on the dimensions of the input array P.

Interpolates outside the bounds of P can be set to a user-specified value by using the MISSING keyword.

Examples

The example below computes bilinear interpolates with the keyword GRID set:

p = FINDGEN(4,4)

PRINT, INTERPOLATE(p, [.5, 1.5, 2.5], [.5, 1.5, 2.5], /GRID)

and prints the 3 by 3 array:

2.50000 3.50000 4.50000

6.50000 7.50000 8.50000

10.5000 11.5000 12.5000

corresponding to the locations:

(.5,.5), (1.5, .5), (2.5, .5),

(.5,1.5), (1.5, 1.5), (2.5, 1.5),

(.5,2.5), (1.5, 2.5), (2.5, 2.5)

Another example computes interpolates, with GRID not set and a parameter outside the bounds of P:

PRINT, INTERPOLATE(p, [.5, 1.5, 2.5, 3.1], [.5, 1.5, 2.5, 2])

and prints the result:

2.50000 7.50000 12.5000 11.0000

corresponding to the locations (.5,.5), (1.5, 1.5), (2.5, 2.5) and (3.1, 2.0). Note that the last location is outside the bounds of P and is set from the value of the last column. The following command uses the MISSING keyword to set such values to -1:

PRINT, INTERPOLATE(p, [.5, 1.5, 2.5, 3.1], [.5, 1.5, 2.5, 2], $

MISSING = -1)

and gives the result:

2.50000 7.50000 12.5000 -1.00000

Syntax

Result = INTERPOLATE( P, X [, Y [, Z]] [, CUBIC=value{-1 to 0}] [, /DOUBLE] [, /GRID] [, MISSING=value] )

IDL> arr1=findgen(2,2)
IDL> print,arr1
0.000000      1.00000
2.00000      3.00000
IDL> print,interpolate(arr1,0.5)
1.00000      2.00000
IDL> print,interpolate(arr1,[0,0.5,1.5])
0.000000      1.00000
1.00000      2.00000
2.00000      3.00000
IDL> print,interpolate(arr1,[0,0.5,1.5],[0,0.5,1.5])
0.000000      1.50000      3.00000
IDL> print,interpolate(arr1,[0,0.5,1.5],[0,0.5,1.5],/grid)
0.000000     0.500000      1.00000
1.00000      1.50000      2.00000
2.00000      2.50000      3.00000


@3、数组反转–REVERSE()

The REVERSE function reverses the order of one dimension of an array.

Syntax

Result = REVERSE( Array [, Subscript_Index] [, /OVERWRITE] )

Subscript_Index

An integer specifying the dimension index (1, 2, 3, etc.) that will be reversed. This argument must be less than or equal to the number of dimensions of Array. If this argument is omitted, the first subscript is reversed.

IDL> print,arr
0       1
2       3
IDL> ;行反转
IDL> print,reverse(arr,1); 1是一维,行优先
1       0
3       2
IDL> ;列反转
IDL> print,reverse(arr,2)
2       3
0       1


@4、数组转置–TRANSPOSE()

The TRANSPOSE function returns the transpose of Array. If an optional permutation vector is provided, the dimensions of Array are rearranged as well.

Syntax

Result = TRANSPOSE( Array [, P] )

P

A vector specifying how the dimensions of Array will be permuted. The elements of P correspond to the dimensions of Array; the ith dimension of the output array is dimension P[i] of the input array. Each element of the vector P must be unique. Dimensions start at zero and can not be repeated.

If P is not present, the order of the dimensions of Array is reversed.

IDL> print,arr
0       1
2       3
IDL> print,transpose(arr,[1,0])
0       2
1       3


@5、数组旋转–ROTATE()

The ROTATE function returns a rotated and/or transposed copy of Array. ROTATE can only rotate arrays in multiples of 90 degrees. To rotate by amounts other than multiples of 90 degrees, use the ROT function. Note, however, that ROTATE is more efficient.

ROTATE can also be used to reverse the order of elements in vectors. For example, to reverse the order of elements in the vector X, use the expression ROTATE(X,2). If X = [0,1,2,3] then ROTATE(X,2)yields the resulting array, [3,2,1,0].

Syntax

Result = ROTATE(Array, Direction)

Direction

Direction specifies the operation to be performed as follows:



图11 旋转-direction

IDL> arr1=indgen(2,3)
IDL> print,arr1
0       1
2       3
4       5
IDL> print,rotate(arr1,1)
4       2       0
5       3       1
IDL> print,rotate(arr1,0)
0       1
2       3
4       5
IDL> print,rotate(arr1,2)
5       4
3       2
1       0
IDL> print,rotate(arr1,3)
1       3       5
0       2       4
IDL> print,rotate(arr1,4)
0       2       4
1       3       5
IDL> print,rotate(arr1,5)
1       0
3       2
5       4
IDL> print,rotate(arr1,6)
5       3       1
4       2       0
IDL> print,rotate(arr1,7)
4       5
2       3
0       1


Rot()函数:

The ROT function rotates an image by an arbitrary amount. At the same time, it can magnify, demagnify, and/or translate an image.

*===============================================================

DIST()函数:

The DIST function creates an array in which each array element value is proportional to its frequency. This array may be used for a variety of purposes, including frequency-domain filtering

Syntax

Result = DIST(N [, M])

N

The number of columns in the resulting array.

M

The number of rows in the resulting array. If M is omitted, the resulting array will be N by N.

IDL> TVSCL,dist(200)




图12 DIST imge

*===============================================================

Syntax

Result = ROT( A, Angle, [Mag, X0, Y0] [, /INTERP] [, CUBIC=value{-1 to 0}] [, MISSING=value] [, /PIVOT] )

ANGLE

Angle of rotation in degrees clockwise.

MAG

An optional magnification factor. A value of 1.0 results in no change. A value greater than one performs magnification. A value less than one but greater than zero performs demagnification.

X0

X subscript for the center of rotation. If omitted, X0 equals the number of columns in the image divided by 2.

Y0

Y subscript for the center of rotation. If omitted, Y0 equals the number of rows in the image divided by 2.

IDL> ; Create a byte image:
IDL> A = BYTSCL(DIST(256))
IDL>
IDL> ; Display it:
IDL> TV, A
IDL>
IDL> ; Rotate the image 33 degrees, magnify it 15 times, and use
IDL> ; bilinear interpolation to make the output look nice:
IDL> B = ROT(A, 33, 1.5, /INTERP)




图12 TV A



图13 TV B

@6、数组平移–Shift()函数

The SHIFT function shifts elements of vectors or arrays along any dimension by any number of elements. Positive shifts are to the right while left shifts are expressed as a negative number. All shifts are circular.

Elements shifted off one end wrap around and are shifted onto the other end. In the case of vectors the action of SHIFT can be expressed:

Result(i + s) modulation = Arrayi for (0 ≤ 1 < n)

where s is the amount of the shift, and n is the number of elements in the array.

Syntax

Result = SHIFT(Array, S1, …, Sn)

IDL> arr=indgen(4,4)
IDL> print,arr
0       1       2       3
4       5       6       7
8       9      10      11
12      13      14      15
IDL> print,shift(arr,1)
15       0       1       2
3       4       5       6
7       8       9      10
11      12      13      14
IDL> print,shift(arr,-2)
2       3       4       5
6       7       8       9
10      11      12      13
14      15       0       1
IDL> print,shift(arr,1,1)
15      12      13      14
3       0       1       2
7       4       5       6
11       8       9      10
IDL> ;数组X方向右移一个元素,Y方向向下移动一个元素


@7、数组排序–Sort()函数

The SORT function returns a vector of subscripts that allow access to the elements of Array in ascending order.

Syntax

Result = SORT(Array [, /L64] )

L64

By default, the result of SORT is 32-bit integer when possible, and 64-bit integer if the number of elements being sorted requires it. Set L64 to force 64-bit integers to be returned in all cases.

Note: Only 64-bit versions of IDL are capable of creating variables requiring a 64-bit sort. Check the value of !VERSION.MEMORY_BITS to see if your IDL is 64-bit or not.

IDL> arr=[5,3,4,2,6,1,34,45]
IDL> print,sort(arr)
5           3           1           2           0           4           6           7
IDL> print,arr(sort(arr))
1       2       3       4       5       6      34      45


@8、求不同值–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.

返回相邻元素不同值的索引,如果先对数组进行排序,则可求出数组中包含的不同值。

IDL> arr=[5,3,4,2,6,1,34,45]
IDL> print,sort(arr)
5           3           1           2           0           4           6           7
IDL> print,arr(sort(arr))
1       2       3       4       5       6      34      45
IDL> arr=[1,2,1,3,3]
IDL> print,arr[uniq(arr)]
1 2 1 3
IDL> print,uniq(arr)
0 1 2 4
IDL> arr=[1,2,1,3,3,3]
IDL> print,uniq(arr)
0 1 2 5
IDL> print,arr(uniq(arr(sort(arr))))
2 1 3


@9、判断数组–Array_Equal()函数

The ARRAY_EQUAL function is a fast way to compare data for equality in situations where the index of the elements that differ are not of interest. This operation is much faster than using TOTAL(A NE B), because it stops the comparison as soon as the first inequality is found, an intermediate array is not created, and only one pass is made through the data. For best speed, ensure that the operands are of the same data type.

Arrays may be compared to scalars, in which case each element in the array is compared to the scalar. For two arrays to be equal, they must have the same number of elements. If the types of the operands differ, the type of the least precise is converted to that of the most precise, unless the NO_TYPECONV keyword is specified to prevent it. This function works on all numeric types, strings, pointer references, and object references. In the case of pointer and object references, ARRAY_EQUAL compares the references (which are long integers), not the heap variables to which the references point.

Syntax

Result = ARRAY_EQUAL( Op1 , Op2 [, /NO_TYPECONV ] )

NO_TYPECONV

By default, ARRAY_EQUAL converts operands of different types to a common type before performing the equality comparison. Set NO_TYPECONV to disallow this implicit type conversion. If NO_TYPECONV is specified, operands of different types are never considered to be equal, even if their numeric values are the same.

IDL> print,arr1
1       1
IDL> print,arr2
1   1
IDL> print,array_equal(arr1,arr2)
1
IDL> print,array_equal(arr1,arr2,/no_typeconv)
0
IDL> help,arr2
ARR2            BYTE      = Array[2]
IDL> help,arr1
ARR1            INT       = Array[2]


@10、求元素个数-N_Elements()函数

IDL> print,N_Elements(arr1)
2


@11、求最大值–Max()函数

The MAX function returns the value of the largest element of Array.

Syntax

Result = MAX( Array [, Max_Subscript] [, /ABSOLUTE] [, DIMENSION=value] [, MIN=variable] [, /NAN] [, SUBSCRIPT_MIN=variable])

MIN

A named variable to receive the value of the minimum array element. If you need to find both the minimum and maximum array values, use this keyword to avoid scanning the array twice with separate calls to MAX and MIN.

IDL> print,arr
23      34     546     567     223
IDL> print,Max(arr)
567
IDL> print,Max(arr,Min=minval)
567
IDL> print,Min
% PRINT: Variable is undefined: MIN.
% Execution halted at: $MAIN$
IDL> print,minval
23


@12、求最小值–Min()函数

同Max函数类似

@13、求和–Total()函数

The TOTAL function returns the sum of the elements of Array. The sum of the array elements over a given dimension is returned if the Dimension argument is present.

Syntax

Result = TOTAL( Array [, Dimension] [, /CUMULATIVE] [, /DOUBLE] [, /INTEGER] [, /NAN] [, /PRESERVE_TYPE] )

CUMULATIVE

If this keyword is set, the result is an array of the same size as the input, with each element, i, containing the sum of the input array elements 0 to i. This keyword also works with the Dimension parameter, in which case the sum is performed over the given dimension. Note that if the input only has a single element, then a scalar is returned.

Tip: If the input array is a temporary variable or an expression, and the result type matches the input type (for example by using the PRESERVE_TYPE keyword), then TOTAL will perform the cumulative sum in place and no additional memory will be used.

IDL> print,a
5.00000     -1.00000      3.00000
2.00000     0.000000      1.00000
3.00000      2.00000      1.00000
IDL> print,total(a)
16.0000
IDL> print,total(a,/cumulative)
5.00000      4.00000      7.00000
9.00000      9.00000      10.0000
13.0000      15.0000      16.0000
IDL> print,total(a,1)
7.00000      3.00000      6.00000
IDL> print,total(a,2)
10.0000      1.00000      5.00000


@14、乘积计算–Product()函数

同Total类似

@15、阶乘计算–Factorial()函数

IDL> print,factorial(6)
720.00000


@16、平均值计算–Mean()函数

IDL> print,a
5.00000     -1.00000      3.00000
2.00000     0.000000      1.00000
3.00000      2.00000      1.00000
IDL> print,mean(a)
1.77778


@17、方差计算–Variance()函数

n-1作为除数

IDL> print,variance(a)
3.19444


@18、标准差计算–Stddev()函数

IDL> print,stddev(a)
1.78730


@19、平均值、方差、倾斜度及频率曲线峰态计算

IDL> print,moment(a)
1.77778      3.19444     0.177792     -1.01256


7、矩阵运算



A#B:a的列乘以B的行

A##B:a的行乘以B的列

IDL> print,b
0       1
2       3
3       4
IDL> print,c
0       1       2
3       4       5
IDL> print,b#c
8          11
23          35
IDL> print,b##c
3           4           5
9          14          19
12          19          26


矩阵求逆

Invert()函数:

The INVERT function uses the Gaussian elimination method to compute the inverse of a square array. Errors from singular or near-singular arrays are accumulated in the optional Status argument.

Syntax

Result = INVERT( Array [, Status] [, /DOUBLE] )

Array

The array to be inverted. Array must have two dimensions of equal size (i.e., a square array) and can be of any type except string. Note that the resulting array will be composed of single- or double-precision floating-point or complex values, depending on whether the DOUBLE keyword is set.

IDL> print,a
5.00000     -1.00000      3.00000
2.00000     0.000000      1.00000
3.00000      2.00000      1.00000
IDL> print,invert(a)
-2.00000      7.00000     -1.00000
0.999999     -4.00000      1.00000
4.00000     -13.0000      2.00000


行列数求值:

DETERM()函数

IDL> print,a
5.00000     -1.00000      3.00000
2.00000     0.000000      1.00000
3.00000      2.00000      1.00000
IDL> print,determ(a)
% Compiled module: DETERM.
1.00000


矩阵乘积

MATRIX_POWER()函数:

The MATRIX_POWER function computes the product of a matrix with itself. For example, the fifth power of array A is A # A # A # A # A. Negative powers are computed using the matrix inverse of the positive power.

Syntax

Result = MATRIX_POWER(Array, N [, /DOUBLE] [, STATUS=value])

N

An integer representing the power. N may be positive or negative.

N个矩阵A相乘

IDL> b=[[2d,3d],[4d,6d]]
IDL> print,b
2.0000000       3.0000000
4.0000000       6.0000000
IDL> print,matrix_power(b,1e2)
5.0925899e+089  7.6388849e+089
1.0185180e+090  1.5277770e+090
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  idl 基础