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 numpy
is newer than the version your colleagues are using (please check using numpy.version.version
). In the 1.7.0 development branch, it seems they've changed the implicit casting rule to the more strict same_kind
rule, which forbids (among other things) casts between floating-point and integer formats.
To work around this, I'd recommend using code like this:
img[:middle] *= (bg[0]/np.tile(topCol, (middle,1))).astype(img.dtype)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With