On Tue, Aug 18, 2009 at 2:01 AM, Maria Liukis<liu...@usc.edu> wrote: > Josef, > Many thanks for the example! It should become an official NumPy recipe :) > Thanks again, > Masha > -------------------- > liu...@usc.edu
Actually, there is also an implementation of unique rows in scipy.stats._support. It uses loops (and array concatenation in the loop), but it preserves the order of the rows in the array. In general, I don't recommend using scipy.stats._support, since many or most functions are not tested and only some are used in scipy.stats. These functions wait for a rewrite or removal. When I thought about a rewrite last year, I didn't know much about structured arrays and views. Josef >>> cc array([[10, 1, 2], [ 3, 4, 5], [ 3, 4, 5], [ 9, 10, 11]]) >>> scipy.stats._support.unique(cc) array([[10, 1, 2], [ 3, 4, 5], [ 9, 10, 11]]) unique columns using transpose : >>> cct = cc.T.copy() >>> cct array([[10, 3, 3, 9], [ 1, 4, 4, 10], [ 2, 5, 5, 11]]) >>> scipy.stats._support.unique(cct.T).T array([[10, 3, 9], [ 1, 4, 10], [ 2, 5, 11]]) Josef > > On Aug 17, 2009, at 10:03 PM, josef.p...@gmail.com wrote: > > On Tue, Aug 18, 2009 at 12:59 AM, Maria Liukis<liu...@usc.edu> wrote: > > On Aug 17, 2009, at 9:51 PM, Charles R Harris wrote: > > On Mon, Aug 17, 2009 at 10:30 PM, Maria Liukis <liu...@usc.edu> wrote: > > Hello everybody, > While re-implementing some Matlab code in Python, I've run into a problem > of finding a NumPy function analogous to the Matlab's "unique(array, > 'rows')" to get unique rows of an array. Searching the web, I've found a > similar discussion from couple of years ago with an example: > > Just to be clear, do you mean finding all rows that only occur once in the > array? > Yes. > > I interpreted your question as removing duplicates. It keeps rows that > occur more than once. > That's what my example is intended to do. > Josef > > <snip> > Chuck > > _______________________________________________ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion > _______________________________________________ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion > > _______________________________________________ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion > > _______________________________________________ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > http://mail.scipy.org/mailman/listinfo/numpy-discussion > > _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion