我正在尝试计算卫星图像的欧氏距离。我的代码适用于小图像,但对于大图像,它是失败的。我收到错误,无法解决。 错误:
Traceback (most recent call last):
File "U:\Annoop_WC\Multiband Spectral Anaysis.py", line 139, in <module>
main()
File "U:\Annoop_WC\Multiband Spectral Anaysis.py", line 72, in main
min = np.amin(np.array(ngbh_matrix)[ngbh_matrix != np.amin(ngbh_matrix)])
File "C:\Python27\ArcGIS10.2\lib\site-packages\numpy\core\fromnumeric.py", line 2354, in amin out=out, keepdims=keepdims)
File "C:\Python27\ArcGIS10.2\lib\site-packages\numpy\core\_methods.py",line 14, in _amin
out=out, keepdims=keepdims)
ValueError: zero-size array to reduction operation minimum which has no identity
代码段:
if np.amin(ngbh_matrix) == noDataValue:
min = np.amin(np.array(ngbh_matrix)[ngbh_matrix != np.amin(ngbh_matrix)])
else:
min = np.amin(ngbh_matrix)
if (np.amax(ngbh_matrix)) == noDataValue:
max = np.amax(np.array(ngbh_matrix)[ngbh_matrix != np.amax(ngbh_matrix)])
else:
max = np.amax(ngbh_matrix)
关于代码的小描述:我正在将图像读入arcpy并将其转换为numpy数组。然后填充以便与nodatavalue形成邻域。如下Nodatavalue = 0。所以我必须找到邻域矩阵的min,它不等于0。
a= |1 2 3 |
|4 5 6 |
|7 8 9 |
neighborhood matrix = |0 0 0|
|0 1 2|
|0 4 5|
请帮助解决错误。