[SciPy-user] counting pairs of values

Zachary Pincus zachary.pincus@yale....
Thu Jul 16 09:48:55 CDT 2009


Check out the discussion from yesterday on the numpy list "Neighbour- 
frequency matrix" for a generalization of this problem. You could also  
use numpy.histogram2d for this.

Zach


On Jul 16, 2009, at 10:01 AM, Ernest Adrogué wrote:

> Hi,
>
> I've got a series of observations that consist of pairs of
> values (x, y) and I'm interested in counting the number of
> occurrences of arbitrary pairs of values.
>
> For example, if "a" is a 2-dimensional array such as
>
> array([[1, 2],
>       [3, 4],
>       [5, 5],
>       [1, 2]])
>
> I want to find out how many (1, 2), or how many (3, 3) there
> are.
>
> Currently I'm doing this:
>
> numpy.logical_and(a[:,0] == 1, a[:,1] == 2).sum()
>
> which seems to work well enough, but I wonder if there's a
> more elegant/correct way of doing it.
>
>
> Ernest
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user



More information about the SciPy-user mailing list