XORing on arrays faster?

Robert Kern kern at caltech.edu
Wed Feb 16 03:54:35 EST 2000


In article <88dhqa$nmi$1 at nnrp1.deja.com>,
	rdudfield at my-deja.com writes:
> Hello,
> 
> Anyone know how to do XORing on arrays fast?
> 
> I do not want to use the Numeric package, for other reasons. 

Out of curiousity, why not?

> So that is
> out of the question. BTW using Numeric XORing two arrays is more than
> four times as fast as this method.
> 
> a = array.array('I',[0]) * 1000
> b = array.array('I','\377\377\377\377') * 1000
> 
> # this is the bit I want done faster :)
> for x in xrange(1000):
>   a[x] = a[x] ^ b[x]
> 
> 
> Also if you know a way to map one sequence onto another fast, I'd like
> to know how to do that too :)

Python 1.5.2 (#0, Sep 13 1999, 09:12:57)  [GCC 2.95.1 19990816 (release)] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import operator
>>> import array
>>> a = array.array('I',[0]) * 1000
>>> b = array.array('I','\377\377\377\377') * 1000
>>> a = array.array('I', map(operator.xor, a, b))

The in-place modification semantics, I can't help you with.  Anyone
else?

> Thanks for any help.
> 
> Rene.

-- 
Robert Kern
kern at caltech.edu

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter



More information about the Python-list mailing list