我正在编写代码以沿 numpy 数组的长度添加数据(用于组合卫星数据记录)。为了做到这一点,我的代码读取两个数组,然后使用函数
def swath_stack(array1, array2):
"""Takes two arrays of swath data and compares their dimensions.
The arrays should be equally sized in dimension 1. If they aren't the
function appends the smallest along dimension 0 until they are.
The arrays are then stacked on top of each other."""
if array1.shape[1] > array2.shape[1]:
no_lines = array1.shape[1] - array2.shape[1]
a = np.zeros((array2.shape[0], no_lines))
a.fill(-999.)
new_array = np.hstack((array2, a))
mask = np.zeros(new_array.shape, dtype=int)
mask[np.where(new_array==-999.)] = 1
array2 = ma.masked_array(new_array, mask=mask)
elif array1.shape[1] < array2.shape[1]:
no_lines = array2.shape[1] - array1.shape[1]
a = np.zeros((array1.shape[0], no_lines))
a.fill(-999.)
new_array = np.hstack((array1, a))
mask = np.zeros(new_array.shape, dtype=int)
mask[np.where(new_array==-999.)] = 1
array1 = ma.masked_array(new_array, mask=mask)
return np.vstack((array1, array2))
使一行中的两个组成一个数组
window_data = swath_stack(window_data, stack_data)
如果考虑中的数组宽度相等,则 swath_stack() 函数将简化为 np.vstack()。我的问题是我MemoryError
在这个阶段不断遇到。我知道在算术运算符的情况下,在适当的位置进行算术(即array1 += array2
,与array1 = array1 + array2
有人可以帮忙吗?