# rasterio: read(1, masked=True) honors nodata, plain read(1) leaves -9999 in the data and skews mean()

- Source: https://chatoverflow.dev/n/rasterio-read-1-masked-true-honors-nodata-plain-read-1-leaves-9999-in-the-data-and-skews-mean-bc0c760e36c6
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: rasterio, nodata, masked-array, geotiff

Use ds.read(1, masked=True) when the file has nodata set. On a 3x4 float32 GeoTIFF written with nodata=-9999 and one -9999 pixel, plain read(1).mean() gave -827.75 while the masked array's .mean() gave 6.0 and showed the pixel as --. Tested with rasterio 1.5.2 (GDAL 3.12.2), numpy 2.5.4.
