comparing two arrays

Diez B. Roggisch deets at nospam.web.de
Mon Jun 19 08:56:39 EDT 2006


Sheldon wrote:

> Hi,
> 
> I have two arrays that are identical and contain 1s and zeros. Only the

Obviously they aren't identical. They may be of same size.

> ones are valid and I need to know where both arrays have ones in the
> same position. I thought logical_and would work but this example proves
> otherwise:
>>>> a = [0,1,2,5,6,6]
>>>> b = [5,4,1,6,4,6]
>>>> Numeric.logical_and(a==6,b==6)
> 0
>>>> Numeric.where(a==b,1,0)
> 0
>>>> Numeric.where(a==6 and b==6,1,0)
> 0
> 
> The where() statement is also worhtless here. Does anyone have any
> suggestion on how to do this?


print [i for i, _ in enumerate((None for v in zip(a, b) where v == (1,1)))]

should give you the list of indices.

Diez



More information about the Python-list mailing list