Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.044 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'element': 0.07; '[1,': 0.09; '[],': 0.09; 'cc:addr:python-list': 0.11; '[3],': 0.16; 'adjacent': 0.16; 'algorithm.': 0.16; 'cc:name:python list': 0.16; 'element.': 0.16; 'nodes': 0.16; 'elements': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'sort': 0.25; 'script': 0.25; 'header:In-Reply-To:1': 0.27; 'points': 0.29; 'message-id:@mail.gmail.com': 0.30; 'url:wiki': 0.31; 'url:wikipedia': 0.31; 'allows': 0.31; 'lists': 0.32; 'me?': 0.32; 'could': 0.34; 'received:google.com': 0.35; 'representing': 0.36; 'url:org': 0.36; 'list': 0.37; 'easily': 0.37; 'follows:': 0.38; 'skip:. 20': 0.38; 'structure': 0.39; 'how': 0.40; 'august': 0.61; 'no.': 0.61; 'numbers': 0.61; 'here:': 0.62; "you'll": 0.62; 'such': 0.63; 'to:addr:gmail.com': 0.65; 'arranged.': 0.84; 'oscar': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=YSOXJIhSNqbRykr3hB6XO4C0Qg4fAUlc3CNe0KIFNmc=; b=yFMll4txSLGig5oZdZGPgrfYqXBfEh8jkj4BUQ3g/1AwlZ2mUs8WjiHQ3dtvRQPKJA SNbl/+WMQvPj/Dj1RUG8AgvHNLLz8cZJgZK3fxtbTEsljkyV9WAL72TmKDOk79QTBa8l wr+75phy7dhdCtIDtZiAgTUpQjvc0aS1PKP9pypFk7heEL0G+hAM6bZ8sML6qzoIgDXL AfdUuTu1+m7kNQnk+ky4Am6KZt8IWuNMboRu9+VdV1VIcy/sCsrSGV5XLbAhRhODUt7N LB8EQP16agRY8phZ6uzXrK1TKMTpGMLCIIj8Ez8M25jXM9k0jirMrQIgvb3VU8jiz50v N1xg== X-Received: by 10.220.164.202 with SMTP id f10mr1216463vcy.25.1377081622979; Wed, 21 Aug 2013 03:40:22 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <56e44970-e672-4ab9-8f7c-2183f287a274@googlegroups.com> References: <56e44970-e672-4ab9-8f7c-2183f287a274@googlegroups.com> From: Oscar Benjamin Date: Wed, 21 Aug 2013 11:40:02 +0100 Subject: Re: Matrix sort To: vijayendramunikoti@gmail.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Python List X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1377081625 news.xs4all.nl 15915 [2001:888:2000:d::a6]:35346 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52763 On 21 August 2013 10:24, wrote: > Hi > I have a matrix of numbers representing the nodal points as follows: > > Element No. Nodes > > 1 1 2 3 4 > 2 5 6 7 8 > 3 2 3 9 10 > ........................... > ........................... > x 9 10 11 12 > ........................... > > so this is a matrix of numbers 4 x n > Elements 1 and 3 are neighbours (as they share nodes 2 3). Similarly elem= ents 3 and x are neighbours (they share nodes 9 and 10). I want to sort the= matrix in such a way all the elements are sequentially arranged. How could= I script it? can any one help me? I think you want a topological sort algorithm. See here: http://en.wikipedia.org/wiki/Topological_sorting Before that though you'll want to preprocess your matrix into a data structure that allows you to easily find the elements adjacent to any given element. A list of lists is one approach: graph =3D [ [3], # nodes adjacent to element 1 [], # element 2 [1, x], # element 3 ... [3] # element x ] Oscar