Question: how to calculate ndvi in python using gdal?
Answer: from osgeo import gdal. import numpy. g = gdal. Open ("baikal_subset.tif") if g is None: b3 = g. GetRasterBand(3). ReadAsArray(). astype(np. float32) b4 = g. GetRasterBand(4). ReadAsArray(). astype(np. float32) ndvi = (b4 - b3)/(b4 + b3) drv = gdal. GetDriverByName ( "GTiff" )