[SciPy-user] Ordering and Counting the Repetitions of the Rows of a Matrix
Lorenzo Isella
lorenzo.isella@gmail....
Sun Jul 27 11:17:47 CDT 2008
Dear All,
Consider an Nx2 matrix of the kind:
A= 1 2
3 13
1 2
6 8
3 13
2 9
1 1
The first entry in each row is always smaller or equal than the second
entry in the same row.
Now there are two things I would like to do with this A matrix:
(1) With a sort of n.unique1d (but have not been very successful yet),
let each row of A appear only once (i.e. get rid of the repetitions).
Therefore one should obtain the matrix:
B= 1 2
3 13
6 8
2 9
1 1
(2) At the same time, efficiently count how many times each row of B
appeared in A. I would like to get a C vector counting them as:
C= 2
2
1
1
1
Any suggestions about an efficient way of achieving this?
Many thanks
Lorenzo
More information about the SciPy-user
mailing list