操作 | 语法 |
---|---|
创建 | ee.Dictionary() |
修改 | dict.combine(); dict.set() |
查询 | dict.keys(); dict.get(); dict.values() |
对比 | dict.contains() |
尺寸 | dict.size() |
字典型数据由关键词和数据组成
var dict = ee.Dictionary({
Name:'SpongeBob',
Gender:'Male',
Age:">20",
Location:"Bikini Bottom"
})
print(dict)
var dict1 = ee.Dictionary({
weight:'50kg',
height:'160cm'
})
var dict2 = ee.Dictionary({
weight:'70kg',
age:'26'
})
var dict_comb = dict1.combine(dict2,true)
print(dict_comb)
var dict1 = ee.Dictionary({
weight:'50kg',
height:'160cm'
})
var dict2 = ee.Dictionary({
weight:'70kg',
age:'26'
})
var dict_comb = dict1.combine(dict2,false)
print(dict_comb)
var dict1 = ee.Dictionary({
weight:'50kg',
height:'160cm'
})
var dict_change = dict1.set('weight','70kg')
print(dict_change)
var dict1 = ee.Dictionary({
weight:'50kg',
height:'160cm'
})
var list_keys = dict1.keys()
print(list_keys)
var dict1 = ee.Dictionary({
weight:'50kg',
height:'160cm'
})
var weight = dict1.get('weight')
print(weight)
var dict1 = ee.Dictionary({
weight:'50kg',
height:'160cm'
})
var value = dict1.values(['weight','height'])
print(value)
var dict1 = ee.Dictionary({
weight:'50kg',
height:'160cm'
})
var bool = dict1.contains('name')
print(bool)
var dict1 = ee.Dictionary({
weight:'50kg',
height:'160cm'
})
var size = dict1.size()
print(size)
操作 | 语法 |
---|---|
创建 | ee.List(); list.repeat(); list.sequence() |
修改 | list.set(); list.replaceAll(); list.add(); list.insert(); list.zip(); list.reverse(); list.rotate(); list.sort(); list.swap(); list.flatten() |
查询 | list.get(); list.remove(); list.removeAll() |
比较 | list.equals(); list.contains(); list.containsAll(); list.indexOf(); list.indexOfSubList(); list.lastIndexOfSublist(); list.frequency() |
其它 | list.map(); list.iterate(); list.length(); list.size() |
var list = ee.List([1,2,3,'A','B','C',['Hello','Good','Bye']])
print(list)
var list = ee.List.repeat('hello',5)
print(list)
var list1 = ee.List.sequence(0,9,1,null)
var list2 = ee.List.sequence(0,9,null,4)
print(list1, list2)
修改某一位的值
var list1 = ee.List([1992,1,20,'hello'])
var list2 = list1.set(0,1993)
var list3 = list2.set(-1, 'world')
print(list1, list2, list3)
替换
var list1 = ee.List([1992,1,20,'hello',1992,1,20,'hello'])
var list2 = list1.replace(1,5)
var list3 = list2.replaceAll(1,5)
print(list1, list2, list3)
var list1 = ee.List([1992,1,20,'hello'])
var list2 = list1.add('Male')
var list3 = list1.insert(3, 'world')
print(list1, list2, list3)
add只是在列表的末尾添加内容
insert可以在指定的位置添加内容
打包
var list1 = ee.List([1992,1,20,'hello'])
var list2 = list1.zip(['Year','Month','Day'])
print(list1, list2)
反转:reverse 和 rotate
var list1 = ee.List([0,1,2,3,4,5,6,7,8,9])
var list2 = list1.reverse()
var list3 = list1.rotate(5)
print(list1, list2, list3)
其中,reverse是将列表翻转,而rotate是将传入的参数作为起点,对列表重新进行排序(传入的参数是列表中的值,而不是序号)
排序
var list1 = ee.List(['Zhao','Wang','Ma','Liu','Bai'])
var list2 = list1.sort()
print(list1, list2)
var list1 = ee.List([1,2,3,4,5,6,7,8,9])
var list2 = list1.swap(5,8)
print(list1, list2)
var list1 = ee.List([[1,2,3,4],[5,6,7,8,9]])
var list2 = list1.flatten()
print(list1, list2)
var list1 = ee.List(['hello','world','GEE'])
var list2 = list1.get(1)
print(list1, list2)
删除
var list1 = ee.List([1,1,2,3,3,2,2,4,5,6])
var list2 = list1.remove(2)
var list3 = list1.removeAll([2,3])
print(list1, list2, list3)
var list1 = ee.List(['zhao','qian','sun','li'])
var list2 = ee.List(['zhao','qian','li','sun'])
var list3 = ee.List(['zhao','qian','li'])
var bool1 = list1.equals(list2)
var bool2 = list1.contains('li')
var bool3 = list1.containsAll(list3)
print(bool1, bool2, bool3)
var list_num = ee.List([1,2,3,4,5,6,4,5,6,5,5,5])
var index_num = list_num.indexOf(5)
var index_sub = list_num.indexOfSublist([4,5,6])
var index_last_sub = list_num.lastIndexOfSubList([4,5,6])
var freq_num = list_num.frequency(5)
print(index_num, index_sub, index_last_sub, freq_num)
indexOf : 第一次出现的序号
indexOfSublist: 连续的序列第一次出现的序号
lastIndexOfSubList: 连续的序列最后一次出现的序号
frequency: 出现的次数
map
对list中的每一个数据进行同样的操作
var list1= ee.List(['zhao','qian','sun','li'])
function Do(name){
return ee.List.repeat(name, 3)
}
var list2 = list1.map(Do)
print(list1, list2)
迭代
var list1= ee.List.sequence(1,100,1)
function Do(num1, num2){
return ee.Number(num1).add(num2)
}
var list2 = list1.iterate(Do, 0)
print(list1, list2)
将1,2传入Do,返回3。每次传入两个变量,然后将变量与0累加。
长度
var list1= ee.List([[1,2],[3,4],[5,6],[7,8]])
var list_length = list1.length()
var list_size = list1.size()
print(list_length, list_size)
用法
功能 | 语法 |
---|---|
创建 | ee.Aray(); ee.Aray.identity(); ee.Array.repeat() |
修改 | array.mask(); array.transpose(); array.uint8(); array.Uint8() |
数学 | array.eq(); array.and(); array.or(); array.round(); array.bitwiseAnd(); array.leftShift() |
创建
var array1 = ee.Array([[1],[2],[3]])
var array2 = ee.Array([[1,2,3]])
print(array1, array2)
var array1 = ee.Array([[1,2],[2,3],[3,4]])
var array2 = array1.repeat(2,3)
print(array1, array2)
var array1 = ee.Array([[1,2],[2,3],[3,4]])
var array2 = ee.Array([[0],[1],[0]])
var array3 = array1.mask(array2)
print(array1, array3)
var array1 = ee.Array([[1,2],[2,3],[3,4]])
var array2 = array1.transpose()
print(array1, array2)
var array1 = ee.Array([[1.1,2.2,3.3],[4.4,5.5,6.6]])
var array2 = array1.uint8() # 8位无符号整型(uint6,uint32,unit64,long,float,double)
print(array1,array2)
var array1 = ee.Array([[1,1],[2,2],[3,3],[4,4]])
var array2 = ee.Array([[1,2],[3,4],[4,3],[2,1]])
var array3 = array1.eq(array2)
print(array1,array2,array3)
不等于 | 大于 | 大于等于 | 小于 | 小于等于 |
---|---|---|---|---|
.neq | .gt | .gte | .lt | .lte |
.neq() | .gt() | .gte() | .lt() | .lte() |
与非结构
var array1 = ee.Array([[1,0],[0,0],[3.14,1.41]])
var array2 = ee.Array([[1,2],[0,0],[3,4]])
var array_and = array1.and(array2)
var array_or = array1.or(array2)
print(array1,array2,array_and,array_or)
方法 | 语法 |
---|---|
.abs() | 绝对值 |
.floor() | 向下取整 |
.round() | 四舍五入 |
.ceil() | 向上取整 |
.sqrt() | 开方 |
.exp() | |
.log() | |
.log10() |
运算
方法 | 语法 |
---|---|
add | 加 |
subtract | 减 |
multiply | 乘 |
divide | 除 |
max | 最大 |
min | |
mod | 求模 |
pow | |
hypot | 求三角形斜边?? |
first | 取第一个值 |
first_nonzero | 第一个非零值 |
sin | |
cos | |
tan | |
sinh | |
cosh | |
tanh | |
acos | |
asin | |
atan |
位运算
var array1 = ee.Array([3,2])
var array2 = ee.Array([3,3])
var array_bit_and = array1.bitwiseAnd(array2)
var array_bit_or = array1.bitwise_or(array2)
print('Bitwise[11,10] and [11,11] =', array_bit_and)
print('Bitwise[11,10] or [11,11] =', array_bit_or)
方法 | 语法 |
---|---|
bitwiseAnd()/bitwise_and() | 与 |
bitwiseOr()/bitwise_or() | 或 |
bitwiseXor()/bitwise_xor() | 异或 |
bitwiseNot()/bitwise_not() | 非 |
位运算-平移
var array1 = ee.Array([1,2,3])
var array_left = array1.leftShift([1,1,1])
var array_right = array1.rightShift([1,1,1])
print(array_left)
print(array_right)