I have a 3D numpy array, arr, with shape m*n*k.
for every set of values along the m axis (e.g. arr[:, 0, 0]) I want to generate a single value to represent this set, so that I may end up with a 2D matrix, n*k.
If a set of values along the m axis is repeated, then we should generate the same value each time. 
I.e it is a hashing problem.
I created a solution to the problem using a dictionary, but it drastically reduces performance. For each set of values, I call this function:
 def getCellId(self, valueSet):
     # Turn the set of values (a numpy vector) to a tuple so it can be hashed
     key = tuple(valueSet)
     # Try and simply return an existing ID for this key
     try:
       return self.attributeDict[key]
     except KeyError:
       # If the key was new (and didnt exist), try and generate a new Id by adding one to the max of all current Id's. This will fail the very first time we do this (as there will be no Id's yet), so in that case, just assign the value '1' to the newId
       try:
         newId = max(self.attributeDict.values()) +1
       except ValueError:
         newId = 1
       self.attributeDict[key] = newId
       return newId
The array itself is typically of the size 30*256*256, so a single set of values will have 30 values. I have hundreds of these arrays to process at any one time. Currently, doing all processing that needs to be done up to calculating the hash takes 1.3s for a block of 100 arrays. Including the hashing bumps that up to 75s.
Is there a faster way to generate the single representative value?
30 x 256 x 256?