# Nice way to iterate through a triangular matrix

**URL:** <https://discourse.julialang.org/t/nice-way-to-iterate-through-a-triangular-matrix/101667>\
**Category:** General Usage\
**Tags:** suggestions\
**Created:** [July 16, 2023, 1:48am UTC](https://discourse.julialang.org/t/nice-way-to-iterate-through-a-triangular-matrix/101667 "2023-07-16T01:48:01Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [July 16, 2023, 2:28pm UTC](https://discourse.julialang.org/t/nice-way-to-iterate-through-a-triangular-matrix/101667/5 "2023-07-16T14:28:15Z")

</div>

> [@Iterating over elements of upper triangular matrix, but cartesian indices are needed](https://discourse.julialang.org/t/iterating-over-elements-of-upper-triangular-matrix-but-cartesian-indices-are-needed/65498):
>
> Basically what I (think) I need is this function: [https://stackoverflow.com/questions/27086195/linear-index-upper-triangular-matrix](https://stackoverflow.com/questions/27086195/linear-index-upper-triangular-matrix) Of course I can just implement it, two lines of code. But that seems something that probably is needed quite frequently in matrix computations, so I am surprised I didn’t find it as a Base function. First I thought that most people would prefer constructing an iterator like (for a 3x3 matrix, for example): julia\> for c in Iterators.filter(c -\> c[1] \< c[2], Carte…

---

_[View the full topic](https://discourse.julialang.org/t/nice-way-to-iterate-through-a-triangular-matrix/101667)._
