FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will……

项目场景:

读取遥感影像


问题描述

FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
if im_data == “None”:

   	dataset = gdal.Open(image)
    im_geotrans = dataset.GetGeoTransform()  # 仿射矩阵
    im_proj = dataset.GetProjection()  # 地图投影信息
    im_data = dataset.ReadAsArray()  # 将数据写成数组,对应栅格矩阵,读进来后空值会变为0
    im_data =np.where(im_data == 0,np.nan,im_data) # 将0设置为空值
    if im_data == "None":
        print("无法打开数据")

原因分析:

元素比较失败


解决方案:

if im_data == "None":替换为if im_data is None:

你可能感兴趣的:(bug记录,1024程序员节,python)