0
$\begingroup$

My program generates orthogonal null space vectors such as this:

{{0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0}, {0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0}, {0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0}, {1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1}, {0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0}}.

My goal is to find the ordering which looks at the first occurrence of 1 within the vector. The desired ordering for the above is {5,1,2,6,3,4} corresponding to

{{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, {0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0}}

Primitive attempts using Ordering and Sort have failed; my hope is someone can save me from the faux pas of a Do loop.

$\endgroup$
2
  • 1
    $\begingroup$ Perhaps Reverse[Ordering[vecs]] ? $\endgroup$
    – ilian
    May 18, 2015 at 15:45
  • $\begingroup$ Yes, that's it as Martimer has shown. Thanks to you both. $\endgroup$
    – dantopa
    May 18, 2015 at 16:26

1 Answer 1

1
$\begingroup$
Ordering[{{0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
{0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0},
{0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0},
{1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1},
{0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0}}]//Reverse

{5, 1, 2, 6, 3, 4}

{{0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
{0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0},
{0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0},
{1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1},
{0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0}}[[{5,1,2,6,3,4}]]

{{1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1},
{0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0},
{0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0},
{0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0},
{0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0},
{0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0}}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.