[Numpy-discussion] upcast

Lars Friedrich lfriedri at imtek.de
Wed Aug 30 11:39:43 CDT 2006


I would like to discuss the following code:

import numpy as N

a = N.array((200), dtype = N.uint8)
print (a * 100) / 100

b = N.array((200, 200), dtype = N.uint8)
print (b * 100) / 100

The first print statement will print "200" because the uint8-value is
cast "upwards", I suppose. The second statement prints "[0 0]". I
suppose this is due to overflows during the calculation.

How can I tell numpy to do the upcast also in the second case, returning
"[200 200]"? I am interested in the fastest solution regarding execution
time. In my application I would like to store the result in an

Thanks for every comment


More information about the Numpy-discussion mailing list