Low and behold, I ran into a regression in numpy.choose after upgrading to 1.5.1. Past versions (and numeric) supported an, as far as I could tell, unlimited number of potential choices. The “new” choose is limited to 32. Here is a post where another user laments the regression.
I have a list with 100 choices (0-99) that I was using to modify an array. As a work around, I am using the following code. Understandably, it is 7 times slower than using choose. I am not a C programmer, and while I would to get in an fix the numpy issue, I wonder what other potentially faster work arounds exist. Thoughts?
d={...} #A dictionary with my keys and their new mappings
for key, value in d.iteritems():
array[array==key]=value
I gather that
dhas the keys0to99. In that case, the solution is really simple. First, write the values ofdin a NumPy arrayvalues, in a way thatd[i] == values[i]– this seems to be the natural data structure for these values anyway. Then you can access the new array with the values replaced byIf you want to modify
arrayin place, simply do