Yet another way with numpy is to use the numpy.select method. Which I find really intutive.
The select method takes two lists as arguments. The first expression in the first list will be reclassified to the first value in the second list. This then follows with the second expression being reclassified to the second value in the second list and so on.
The following example reclassifies an aspect raster. Classifying north facing slopes as 1 and everything else as NoData. data is a numpy array of the aspect tif.
outData = numpy.select([data == -9999, (data >= 0) & (data <= 67.5),
(data > 67.5) & (data < 292), data >=272],[-9999,1,-9999,1])
The first expression:
data == -9999
matches the first value -9999 in the second list preserving NoData values.
The second expression in the list:
(data >= 0) & (data <= 67.5)
Corresponds to the second value in the second list 1 and will be reclassify as 1.
The third expression in the first list:
(data > 67.5) & (data < 292)
Corresponds with the third value in te second list -9999 and classify the data as -9999.
The fourth expression in the list:
data >=272
Corresponds with the fourth value in the second list 1 and will be reclassied it as 1.