“数组”的版本间差异
跳到导航
跳到搜索
无编辑摘要 |
无编辑摘要 |
||
(未显示同一用户的2个中间版本) | |||
第6行: | 第6行: | ||
A=reform(data[1,*]) |
A=reform(data[1,*]) |
||
* 中位值 |
|||
a=median(A,/even);偶数位的数据,取中间两个数的平均值 |
|||
* rotate |
* rotate |
||
第40行: | 第42行: | ||
:数组的位数, |
:数组的位数, |
||
print,size(array) |
print,size(array) |
||
:size 还可以用来确定 |
:size 还可以用来确定变量的类型 Ctype=size(A,/type), |
||
* 数组随机打乱(shuffle) |
* 数组随机打乱(shuffle) |
||
第50行: | 第52行: | ||
*数组求和 |
*数组求和 |
||
a=total(indgen(10),/cum);输出为数组的累计分布 |
a=total(indgen(10),/cum);输出为数组的累计分布 |
||
==数组和矩阵运算== |
|||
*For A # B, where A and B are vectors, IDL performs A # TRANSPOSE(B). In this case, C = A # B is a matrix with Cij = Ai Bj. Mathematically, this is equivalent to the outer product, usually denoted by A Å B. |
|||
*For A ## B, where A and B are vectors, IDL performs TRANSPOSE(A) ## B. In this case, C = A ## B is a matrix with Cij = Bi Aj. |
|||
*To compute the dot product, usually denoted by A • B, use TRANSPOSE(A) # B. |
|||
*A # B = B ## A |
|||
*A # B = (BT # AT)T ;T表示转置运算 |
2017年1月9日 (一) 04:37的最新版本
数组
- REFORM 数组变形
- 将数组变为制定的维数
A=indgen(20), B=reform(A,2,10)
- reform在默认(无输入参数)的情况下将数组变为一维
A=reform(data[1,*])
- 中位值
a=median(A,/even);偶数位的数据,取中间两个数的平均值
- rotate
- 可以把数组旋转后组成矩阵,类似于列操作。
a=indgen(10) b=indgen(10) c=[rotate(a,1),rotate(b,10]
- 转置
IDL>print,transpose([a,b])
- reverse
- 数组反向
- 例:数组降序排列,结合sort(默认升序)
PRINT, 'Elements of A in descending order: ', A[REVERSE(SORT(A))]
- 扩维
IDL>print,fan(indgen(3),2) IDL>print,fan(indgen(3),2,/trans)
可以用rebin实现
IDL>print,rebin(indgen(3),3,2)
- 多维数组的位置
- 用array_indices
array = RANDOMU(seed, 10, 10) mx = MAX(array, location) ind=array_indices(array,location) print, ind, array[ind[0],ind[1]], format = '(%"Value at [%d, %d] is %f")'
IDL prints: Value at [3, 6] is 0.973381
- 数组的位数,
print,size(array)
- size 还可以用来确定变量的类型 Ctype=size(A,/type),
- 数组随机打乱(shuffle)
Arr_S=arr[sort(randomu(seed,N_elements(arr))]
- 数组去重
Arr=Arr[uniq(Arr,sort(arr))
- 数组求和
a=total(indgen(10),/cum);输出为数组的累计分布
数组和矩阵运算
- For A # B, where A and B are vectors, IDL performs A # TRANSPOSE(B). In this case, C = A # B is a matrix with Cij = Ai Bj. Mathematically, this is equivalent to the outer product, usually denoted by A Å B.
- For A ## B, where A and B are vectors, IDL performs TRANSPOSE(A) ## B. In this case, C = A ## B is a matrix with Cij = Bi Aj.
- To compute the dot product, usually denoted by A • B, use TRANSPOSE(A) # B.
- A # B = B ## A
- A # B = (BT # AT)T ;T表示转置运算