[SciPy-user] Ordering and Counting the Repetitions of the Rows of a Matrix

David M. Kaplan David.Kaplan@ird...
Sun Jul 27 12:31:01 CDT 2008


Hi,

This is related to the discussion of "unique, sort, rows" that is just
before this email.  Unfortunately, unique1d doesn't have a rows option
(yet).  But I saw an email post that had a good suggestion that may work
for you: hash your array so that you can get the almost certainly unique
rows (essentially infinitesimal chance of getting a false match):

B = rand(A.shape[1],1)
C = dot(A,B)

I,C2 = unique1d(C,return_index=True)

Aunique = A[I,:]
Anum=[]
for a in Aunique:
	Anum.append( sum(all(A==a,axis=1)) )

This will do basically what you want.  Aunique won't be sorted
correctly, but you can use lexsort to fix that (see me recent post).

Cheers,
David

-- 
**********************************
David M. Kaplan
Charge de Recherche 1
Institut de Recherche pour le Developpement
Centre de Recherche Halieutique Mediterraneenne et Tropicale
av. Jean Monnet
B.P. 171
34203 Sete cedex
France

Phone: +33 (0)4 99 57 32 27
Fax: +33 (0)4 99 57 32 95
http://www.ur097.ird.fr/team/dkaplan/index.html
**********************************




More information about the SciPy-user mailing list