[Tutor] comparing two numpy arrays
Mike Hansen
Mike.Hansen at atmel.com
Tue Aug 7 16:35:29 CEST 2007
> From: tutor-bounces at python.org
> [mailto:tutor-bounces at python.org] On Behalf Of Andy Cheesman
>
> Hi people,
>
> If I've two numpy arrays, is there a non-looping way of finding common
> values. (the example below has identical shapes for the
> arrays but this
> may not be the case in my scenario)
>
> e.g
> a = array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
> b = array([ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])
>
> answer = array([ 5,6,7,8,9])
>
> Thanks
>
> Andy
You might try sets.
http://docs.python.org/lib/types-set.html
I'm guessing that you'd need to convert the arrays to sets. Maybe
convert the arrays to lists or tuples then to sets? Maybe you might be
able to directly convert the numpy arrays to sets? I haven't used numpy,
so you'll need to experiment.
Mike
More information about the Tutor
mailing list