[Numpy-discussion] Comparison of arrays

Nils Wagner nwagner@iam.uni-stuttgart...
Mon Feb 9 03:00:05 CST 2009


On Mon, 9 Feb 2009 09:45:02 +0100
  Francesc Alted <faltet@pytables.org> wrote:
> A Monday 09 February 2009, Nils Wagner escrigué:
>> Hi all,
>>
>> I have two integer arrays of different shape, e.g.
>>
>> >>> a
>>
>> array([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10])
>>
>> >>> b
>>
>> array([ 3,  4,  5,  6,  7,  8,  9, 10])
>>
>> How can I extract the values that belong to the array a
>> exclusively i.e. array([1,2]) ?
> 
> One possible, fast solution is using Python sets:
> 
> In [45]: np.array(list(set(a) ^ set(b)))
> Out[45]: array([1, 2])
> 
> Although this is suboptimal for very large arrays as it 
>needs temporary 
> space.
> 
> Cheers,
> 
> -- 
>Francesc Alted
  
Thank you very much for your prompt response.

    Nils


More information about the Numpy-discussion mailing list