difference between 2 arrays

David Robinow drobinow at gmail.com
Wed Aug 19 11:15:07 EDT 2009


On Wed, Aug 19, 2009 at 4:48 AM, Pierre<pierre.gaillard at gmail.com> wrote:
> Hello,
>
> I would like to know how to find the difference (set operation)
> between 2 arrays :
>
> a = array([1,2, 3,2,5,2])
> b = array([1,2])
> I want a - b = [3,5]
>
> Well, the equivalence of setdiff in matlab...
>
> I thought a.difference(b) could work, but no : AttributeError:
> 'numpy.ndarray' object has no attribute 'difference'
>
> Thanks !
> --
> http://mail.python.org/mailman/listinfo/python-list
>

import numpy
a = numpy.array([1,2,3,2,5,2])
b = numpy.array([1,2])
c = list(set(a)-set(b))
# or c = numpy.array(list(set(a)-set(b)))   if you want to continue w/ arrays
print c



More information about the Python-list mailing list