import arcpy import numpy as np import numpy.ma as ma inRaster = r"E:\testraster.tif" # convert inraster to numpy array, set nodata values to -9999 npArray = arcpy.RasterToNumPyArray(inRaster,"","","",-9999) # mask the non-nodata values, and take them out by compressing npM = ma.masked_where(npArray <> -9999, npArray).compressed() # print how many cells are nodata print len(npM)
import arcpy import numpy as np import numpy.ma as ma inRaster=r"E:\test1.tif" # convert inraster to numpy array, set nodata values to -9999 npArray = arcpy.RasterToNumPyArray(inRaster,"","","",-9999) # mask the non-nodata values, and take them out by compressing npM = ma.masked_where(npArray <> -9999, npArray).compressed() print npM.size