[Numpy-discussion] some casting oddness?
jake at edge2.net
Mon Jun 3 07:45:16 EDT 2002
I am using both MA and Numeric in a program that I am writing and ran into
some typecasting oddness (at least I thought it was odd). When using only
Numeric, adding an array of typecode 'l' and one of typecode '1' produces
an array of typecode 'l' whereas using an MA derived array of typecode '1'
added to a Numeric array of typecode 'l' produces an array of typecode '1'.
Sorry if that is a bit dense, the upshot is that mixing the two causes the
output to be the _smaller_ of the two types (Int8 == '1') rather than the
larger (Int == 'l') as I would expect ... below is some code that reproduces
the problem (it may look contrived (and is), but it comes from the guts of
some code I have been playing with):
from Numeric import *
a = zeros((10,))
b = MA.ones((10,),Int8)
b = MA.masked_where(MA.equal(b,1),b,0)
z = ones((10,),Int8)
c = add(a,b.mask())
d = add(a,z)
I get output like:
More information about the NumPy-Discussion