[Numpy-discussion] some casting oddness?

Jake Edge 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):

#!/usr/bin/env python

from Numeric import *
import MA

a = zeros((10,))
print a.typecode()
b = MA.ones((10,),Int8)
b = MA.masked_where(MA.equal(b,1),b,0)
print b.typecode()
print b.mask().typecode()
z = ones((10,),Int8)
print z.typecode()
c = add(a,b.mask())
print c.typecode()
d = add(a,z)
print d.typecode()

I get output like:


any thoughts?



More information about the NumPy-Discussion mailing list