MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: sort and positon matrix element help

  • To: mathgroup at smc.vnet.net
  • Subject: [mg73064] Re: sort and positon matrix element help
  • From: Paul Abbott <paul at physics.uwa.edu.au>
  • Date: Thu, 1 Feb 2007 02:46:47 -0500 (EST)
  • Organization: The University of Western Australia
  • References: <epp6nn$dcl$1@smc.vnet.net>

In article <epp6nn$dcl$1 at smc.vnet.net>,
 "comp.soft-sys.math.mathematica" <phdrelated at gmail.com> wrote:

> I have a large matrix(m*n). I wanna to sort out the matrix 
> from large to small according to its element's value AND save the 
> corresponding row and column number as its position. 

Here is one way using SparseArray, ArrayRules, and Sort:

 SeedRandom[10]

 mat = Table[Random[Real, {-100, 100}], {10}, {15}];

 Sort[Most[ArrayRules[SparseArray[mat]]], Last[#2] < Last[#1] & ]

 {{3, 5} -> 99.1349, {10, 3} -> 98.9494, ...}

Cheers,
Paul

_______________________________________________________________________
Paul Abbott                                      Phone:  61 8 6488 2734
School of Physics, M013                            Fax: +61 8 6488 1014
The University of Western Australia         (CRICOS Provider No 00126G)    
AUSTRALIA                               http://physics.uwa.edu.au/~paul


  • Prev by Date: Re: rather complicated NonlinearFit
  • Next by Date: Re: & without #
  • Previous by thread: Re: rather complicated NonlinearFit
  • Next by thread: Re: sort and positon matrix element help