# 1-based indexing not used consistently?

**URL:** <https://discourse.julialang.org/t/1-based-indexing-not-used-consistently/2284>\
**Category:** General Usage\
**Created:** [February 24, 2017, 7:55pm UTC](https://discourse.julialang.org/t/1-based-indexing-not-used-consistently/2284 "2017-02-24T19:55:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ndbecker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ndbecker/32/10829_2.png) [@ndbecker](https://discourse.julialang.org/u/ndbecker)\
**Post date:** [February 24, 2017, 7:55pm UTC](https://discourse.julialang.org/t/1-based-indexing-not-used-consistently/2284/1 "2017-02-24T19:55:52Z")

</div>

I’m not a fan of 1-based index, but that’s not my question/comment. I just noticed the docstring for  
diagm(v, k::Integer=0)  
Isn’t this inconsistent? (why isn’t the value of k corresponding to the first diagonal k=1?)

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [February 24, 2017, 8:02pm UTC](https://discourse.julialang.org/t/1-based-indexing-not-used-consistently/2284/2 "2017-02-24T20:02:59Z")

</div>

The “zeroth” diagonal is called the main diagonal, then comes the “first diagonal” etc. This is just to use the standard terminology for banded matrices.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [February 24, 2017, 8:41pm UTC](https://discourse.julialang.org/t/1-based-indexing-not-used-consistently/2284/3 "2017-02-24T20:41:18Z")

</div>

And to expand, it makes things make sense because then you can have the first diagonal (1) be the first diagonal above the main diagonal, and in the other direction the -1 diagonal be the first below it. This centers everything at zero, which is nice because lots of banded matrices are symmetric. This creates a good indexing for matrix bands.

But arrays are not symmetric about zero (you’re not indexing -N to N… in most cases), so it’s not like this argument carries over in any sensible way to the way other things should be indexed.
