[SciPy-user] counting pairs of values

Ernest Adrogué eadrogue at gmx.net
Thu Jul 16 10:01:54 EDT 2009


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



More information about the SciPy-User mailing list