[Numpy-discussion] (arange(2, typecode=Complex) % 2).typecode()
Charles G Waldman
cgw at fnal.gov
Fri Jun 2 12:41:51 EDT 2000
Jean-Bernard Addor writes:
> Hey again!
>
> Why is (arange(2, typecode=Complex) % 2).typecode() object and not
> complex?
Looks like a bug to me!
>>> x=arange(2, typecode=Complex)
>>> x
array([ 0.+0.j, 1.+0.j])
>>> x+10
array([ 10.+0.j, 11.+0.j])
>>> x*10
array([ 0.+0.j, 10.+0.j])
>>> x/10
array([ 0. +0.j, 0.1+0.j])
>>> x%10
array([0j , (1+0j) ],'O')
I don't see (offhand) why other operations leave the array as complex,
and "%" causes it to be an 'O'. Presumably complex arrays lack the
"mod" method and are getting promoted to Object. However, for float
and double arrays you get the expected behavior:
>>> x=arange(2, typecode=Float)
>>> x%10
array([ 0., 1.])
More information about the NumPy-Discussion
mailing list