I am running python 2.7 on my Mac, and I’m working on a group coding project with other people using Ubuntu. Every once and a while, code they write won’t work on my computer due to casting rule errors:
273 # Apply column averages to image
--> 274 img[:middle] *= (bg[0]/np.tile(topCol, (middle,1)))
275 img[middle:] *= bg[1]/np.tile(botCol, (middle,1))
276
TypeError: Cannot cast ufunc multiply output from dtype('float64') to dtype('int16') with casting rule 'same_kind'
I don’t think you need the specifics, since this happens in a few different places with different number types.
It works on all of their computers no problem. Everything I write works for them, but every so often what they write doesn’t work for me.
Is there a reason why our machines don’t agree and is there a way I can change things on my end?
Thanks!
This thread suggests that your
numpyis newer than the version your colleagues are using (please check usingnumpy.version.version). In the 1.7.0 development branch, it seems they’ve changed the implicit casting rule to the more strictsame_kindrule, which forbids (among other things) casts between floating-point and integer formats.To work around this, I’d recommend using code like this: