comparing two arrays

Bas wegwerp at gmail.com
Mon Jun 19 10:23:36 EDT 2006


You are comparing a normal python list to a constant, which are
obviously unequal. Try converting your lists to arrays first
(untested):

import numeric/numpy as N
a =N.array([0,1,2,5,6,6])
b = N.array([5,4,1,6,4,6])
print a==6 and b==6
print N.where(a==6 and b==6)

hth,
Bas



Sheldon wrote:
> Hi,
>
> I have two arrays that are identical and contain 1s and zeros. Only the
> 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?
> 
> Thanks in advance,
> Sheldon




More information about the Python-list mailing list