Earth Engine 表示 1-D 向量、2-D 矩阵、3-D 立方体和具有该ee.Array
类型的更高维超立方体。数组是一种灵活的数据结构,但为了换取它们提供的强大功能,它们的伸缩性不如地球引擎中的其他数据结构。如果问题可以在不使用数组的情况下解决,那么结果的计算速度会更快、效率更高。但是,如果问题需要更高维度的模型、灵活的线性代数或任何其他数组特别适合的东西,则可以使用Array
该类。
这里官方给出了一个简单的教学方案:
https://youtu.be/-qo8L5GmKO0
数组维度、形状和大小
数组的维数是指底层数据沿其变化的轴数。例如,0-D 数组是标量数,1-D 数组是向量,2-D 数组是矩阵,3-D 数组是立方体,>3-D 数组是超立方体。对于一个 N 维数组,从 0 到 N-1 有 N 个轴。阵列的形状由轴的长度决定。轴的长度是沿它的位置数。数组大小或数组中的总元素数等于轴长度的乘积。每个轴上每个位置的每个值都必须有一个有效数字,因为当前不支持稀疏或参差不齐的数组。数组的元素类型表示每个元素是什么类型的数字;数组的所有元素都将具有相同的类型。
Earth Engine 中的数组由数字列表和列表列表构成。嵌套的程度决定了维数。要从一个简单的、有动机的示例开始,请考虑以下Array
从 Landsat 5 tasseled cap (TC) 系数(Crist 和 Cicone 1984)创建的案例:
函数:
length()
Returns a 1-D EEArray containing the length of each dimension of the given EEArray.
Arguments:
this:array (Array):
The array from which to extract the axis lengths.
Returns: Array
下表说明了矩阵条目沿 0 轴和 1 轴的排列:0为竖轴,1为横轴。
1 轴 -> | |||||||
0 | 1 | 2 | 3 | 4 | 5 | ||
0 | 0.3037 | 0.2793 | 0.4743 | 0.5585 | 0.5082 | 0.1863 | |
1 | -0.2848 | -0.2435 | -0.5436 | 0.7243 | 0.0840 | -0.1800 | |
0轴 | 2 | 0.1509 | 0.1973 | 0.3279 | 0.3406 | -0.7112 | -0.4572 |
3 | -0.8242 | 0.0849 | 0.4392 | -0.0580 | 0.2012 | -0.2768 | |
4 | -0.3280 | 0.0549 | 0.1075 | 0.1855 | -0.4357 | 0.8085 | |
5 | 0.1084 | -0.9022 | 0.4120 | 0.0573 | -0.0251 | 0.0238 |
表格左侧的索引表示沿 0 轴的位置。0 轴上每个列表中的第 n 个元素位于 1 轴上的第 n 个位置。例如,数组坐标 [3,1] 处的条目是 0.0849。假设“绿色度”是感兴趣的 TC 分量。您可以使用slice()
以下方法获得绿色子矩阵:
函数:
slice(axis, start, end, step)
Creates a subarray by slicing out each position along the given axis from the 'start' (inclusive) to 'end' (exclusive) by increments of 'step'. The result will have as many dimensions as the input, and the same length in all directions except the slicing axis, where the length will be the number of positions from 'start' to 'end' by 'step' that are in range of the input array's length along 'axis'. This means the result can be length 0 along the given axis if start=end, or if the start or end values are entirely out of range.
Arguments:
this:array (Array):
Array to slice.
axis (Integer, default: 0):
The axis to slice on.
start (Integer, default: 0):
The coordinate of the first slice (inclusive) along 'axis'. Negative numbers are used to position the start of slicing relative to the end of the array, where -1 starts at the last position on the axis, -2 starts at the next to last position, etc.
end (Integer, default: null):
The coordinate (exclusive) at which to stop taking slices. By default this will be the length of the given axis. Negative numbers are used to position the end of slicing relative to the end of the array, where -1 will exclude the last position, -2 will exclude the last two positions, etc.
step (Integer, default: 1):
The separation between slices along 'axis'; a slice will be taken at each whole multiple of 'step' from 'start' (inclusive) to 'end' (exclusive). Must be positive.
Returns: Array
注:观察start
和end
参数slice()
对应于表中显示的 0 轴索引(start
包含和end
不包含)。我在函数当中标红了