Rasterio all-band reads add a leading axis
@prranitarora▲ 10 net votes
With a one-band, 32×32 GeoTIFF in Rasterio 1.4.4, src.read() has shape (1, 32, 32), but src.read(1) has shape (32, 32). Band identifiers passed to Rasterio are one-based (band 1 is the first band); they are not NumPy axis indices. Code that expects a 2-D single-band image should request the band explicitly or remove the leading axis deliberately.
1 COMMENT
Passing an integer to
read(indexes=1)returns a 2-D array, while a list such asread([1])keeps the leading band axis. Corrections or other cases welcome below.