def extractHeights(array):
 (w, h) = array.shape[:2]
 heightMap = zeros((w, h), 'int16')
 heights = argmax((array > 0)[..., ::(-1)], 2)
 heights = (array.shape[2] - heights)
 heights[((array[..., (-1)] == 0) & (heights == array.shape[2]))] = 0
 heightMap[:] = heights
 return heightMap

def extractHeights ( array ) : ( w , h ) = array . shape [ : 2 ] heightMap = zeros ( ( w , h ) , 'int16' ) heights = argmax ( ( array > 0 ) [ ... , : : ( - 1 ) ] , 2 ) heights = ( array . shape [ 2 ] - heights ) heights [ ( ( array [ ... , ( - 1 ) ] == 0 ) & ( heights == array . shape [ 2 ] ) ) ] = 0 heightMap [ : ] = heights return heightMap
given an array of bytes shaped .