Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52759 > unrolled thread
| Started by | vijayendramunikoti@gmail.com |
|---|---|
| First post | 2013-08-21 02:24 -0700 |
| Last post | 2013-08-21 11:40 +0100 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
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
| From | vijayendramunikoti@gmail.com |
|---|---|
| Date | 2013-08-21 02:24 -0700 |
| Subject | Matrix sort |
| Message-ID | <56e44970-e672-4ab9-8f7c-2183f287a274@googlegroups.com> |
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? Thanks! Vijayendra
[toc] | [next] | [standalone]
| From | Oscar Benjamin <oscar.j.benjamin@gmail.com> |
|---|---|
| Date | 2013-08-21 11:40 +0100 |
| Message-ID | <mailman.77.1377081625.19984.python-list@python.org> |
| In reply to | #52759 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web