comparing two arrays

2006-06-19 Thread Sheldon
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=

Re: comparing two arrays

2006-06-19 Thread Diez B. Roggisch
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 p

Re: comparing two arrays

2006-06-19 Thread Bas
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,

Re: comparing two arrays

2006-06-19 Thread Diez B. Roggisch
Diez B. Roggisch wrote: > print [i for i, _ in enumerate((None for v in zip(a, b) where v == > (1,1)))] > > should give you the list of indices. I musunderstood your question. Use print [i for i, _ in enumerate((None for x, y in zip(a, b) where x == y))] instead. Diez -- http://mail.python.

Re: comparing two arrays

2006-06-19 Thread Robert Kern
Bas wrote: > 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) Car

Re: comparing two arrays

2006-06-20 Thread Sheldon
Diez B. Roggisch skrev: > Diez B. Roggisch wrote: > > > print [i for i, _ in enumerate((None for v in zip(a, b) where v == > > (1,1)))] > > > > should give you the list of indices. > > I musunderstood your question. Use > > > print [i for i, _ in enumerate((None for x, y in zip(a, b) where x == y

Re: comparing two arrays

2006-06-20 Thread Diez B. Roggisch
>> print [i for i, _ in enumerate((None for x, y in zip(a, b) where x == >> y))] >> >> instead. >> >> Diez > > Hi Diez, > > I wish I say that I understood what you wrote here but I can't. > Do you mind explaining a little more? I actually made a typo, instead of "where" in the above use "if". an

Re: comparing two arrays

2006-06-20 Thread Maric Michaud
Le Mardi 20 Juin 2006 12:09, Diez B. Roggisch a écrit : > [i for i, equals in enumerate((x == y for x, y in zip(a, b))) if equals] No needs to nest comprehensions, should be : [ i for i, v in enumerate(zip(a, b)) if v[0] == v[1] ] -- _ Maric Michaud _ Aristote - www.a

Re: comparing two arrays

2006-06-20 Thread Diez B. Roggisch
Maric Michaud wrote: > Le Mardi 20 Juin 2006 12:09, Diez B. Roggisch a écrit : >> [i for i, equals in enumerate((x == y for x, y in zip(a, b))) if equals] > > No needs to nest comprehensions, should be : > > [ i for i, v in enumerate(zip(a, b)) if v[0] == v[1] ] You're right, that design stemme

Re: comparing two arrays

2006-06-20 Thread Scott David Daniels
Diez B. Roggisch wrote: > Maric Michaud wrote: > >> Le Mardi 20 Juin 2006 12:09, Diez B. Roggisch a écrit : >>> [i for i, equals in enumerate((x == y for x, y in zip(a, b))) if equals] >> No needs to nest comprehensions, should be : >> [ i for i, v in enumerate(zip(a, b)) if v[0] == v[1] ] > > Yo

Re: comparing two arrays

2006-06-22 Thread Sheldon
Thanks Diez, It will take a little while for this one to sink in but it gets the job done now and will for future cases. /Sheldon Diez B. Roggisch skrev: > >> print [i for i, _ in enumerate((None for x, y in zip(a, b) where x == > >> y))] > >> > >> instead. > >> > >> Diez > > > > Hi Diez, > > >

Re: comparing two arrays

2006-06-22 Thread Sheldon
Thanks Diez, It will take a little while for this one to sink in but it gets the job done now and will for future cases. /Sheldon Diez B. Roggisch skrev: > >> print [i for i, _ in enumerate((None for x, y in zip(a, b) where x == > >> y))] > >> > >> instead. > >> > >> Diez > > > > Hi Diez, > > >