no data exclution and unique combination.

Terry Reedy tjreedy at udel.edu
Thu Aug 9 17:33:58 EDT 2012


On 8/9/2012 4:06 PM, giuseppe.amatulli at gmail.com wrote:
> Terry and MRAB,
> thanks for yours suggestions,
> in the end i found this solution
>
>
> mask=( a != 0 ) & ( b != 0  )
>
> a_mask=a[mask]
> b_mask=b[mask]
>
> array2D = np.array(zip(a_mask,b_mask))
>
> unique=dict()
> for row in  array2D :
>      row = tuple(row)
>      if row in unique:
>          unique[row] += 1
>      else:
>          unique[row] = 1

I believe the 4 lines above are equivalent to
    unique[row] = unique.get(row, 0) + 1

-- 
Terry Jan Reedy




More information about the Python-list mailing list