Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52763
| References | <56e44970-e672-4ab9-8f7c-2183f287a274@googlegroups.com> |
|---|---|
| From | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
| Date | 2013-08-21 11:40 +0100 |
| Subject | Re: Matrix sort |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.77.1377081625.19984.python-list@python.org> (permalink) |
On 21 August 2013 10:24, <vijayendramunikoti@gmail.com> 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 elements 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 = [
[3], # nodes adjacent to element 1
[], # element 2
[1, x], # element 3
...
[3] # element x
]
Oscar
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Matrix sort vijayendramunikoti@gmail.com - 2013-08-21 02:24 -0700 Re: Matrix sort Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-08-21 11:40 +0100
csiph-web