difference between 2 arrays
robert.kern at gmail.com
Wed Aug 19 18:17:16 CEST 2009
On 2009-08-19 01:48 AM, Pierre wrote:
> 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...
You will want to ask numpy questions on the numpy mailing list.
Using set() is frequently a good option, but for large arrays, you will want to
avoid the overhead of converting to and from sets and use numpy.setdiff1d(a, b):
In : a = array([1,2, 3,2,5,2])
In : b = array([1,2])
In : numpy.setdiff1d(a, b)
Out: array([3, 5])
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list