import gdal from Scripts.gdalimport import dataset import numpy as np filename = 'filename.tif' # E:\pythonProject dataset = gdal.Open(filename) im_data = dataset.ReadAsArray(0, 0, im_width, im_height) # 获取数据im_data{ndarry:(2867,2804)} im_NIR = im_data[6, 0:im_height, 0:im_width] # 获取近红外波段,第m八波段im_NIR{ndarry:(2867,2804)} im_RED = im_data[3, 0:im_height, 0:im_width] # 获取红外波段,第四波段im_RED{ndarry:(2867,2804)} NDVI = (im_NIR - im_RED) / (im_NIR + im_RED) # 计算出NDVI{ndarry:(2867,2804)} if NDVI <= 0.17: VWC = 0 if NDVI > 0.5: VWC = 4.2857 * NDVI - 1.5429 if NDVI <= 0.5 and NDVI > 0.17: VWC = 1.9134 * NDVI ** 2 - 0.3215 * NDVI print (VWC)
报错:ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
我想计算VWC,VWC是根据NDVI每一个数大小不同计算得出来的,可是我用if结果就报错,(我觉得用a.any和a.all都不对)也试了很多方法都算不出来,本人0基础,有没有大佬帮忙指点一下,应该用什么方法才能把VWC计算出来呢