Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • 2
    $\begingroup$ Very clever! SparseArray[l]["AdjacencyLists"] returns the same thing as Complement[Range[Length[l]], Flatten@Position[l, 0]] I really need to learn more about SparseArray. $\endgroup$ Commented Sep 14, 2012 at 23:10
  • 1
    $\begingroup$ You can eliminate some redundancy with: davidZC2[l_] := Module[{z, c}, z[k_] := SparseArray[k]["AdjacencyLists"]; c = z[l]; {c[[#]], c[[# + 1]]}\[Transpose] &@z[Differences@Sign@l[[c]]]] $\endgroup$ Commented Sep 14, 2012 at 23:35
  • $\begingroup$ @David links to other uses are found in this post. $\endgroup$ Commented Sep 15, 2012 at 12:15
  • $\begingroup$ @David I included your suggestion in my latest update, but in my own style. :-) $\endgroup$ Commented Jan 5, 2014 at 21:04