3 ms·
For math too, 0-based indexing is superior. When taking sub-matrices (blocks), with 1-based indexing you have to deal with + 1 and - 1 terms for the element in
by Aardwolf 2y ago
For math too, 0-based indexing is superior. When taking sub-matrices (blocks), with 1-based indexing you have to deal with + 1 and - 1 terms for the element indices. E.g. the third size-4 block of a 16x16 matrix begins at (3-1)*4+1 in 1-based indexing, at 2*4 in 0-based indexing (where the 2 is naturally the 0-indexed block index).
Also, the origin is at 0, not at 1. If you begin at 1, you've already moved some distance away from the origin at the start.
- shiandow 2y agoIn mathematics, if it matters what index your matrix starts on then you're likely doing something wrong. Besides, in the rare cases where it does matter you're free to pick whichever is convenient.
- deleted 2y ago[deleted]
- venusenvy47 2y agoJust speaking anecdotally, I had the impression that math people prefer 1-based indexing. I've heard that Matlab is 1-based because it was written by math majors, rather than CS majors.
- Aardwolf 2y agoYes but I think it might be just habit, and it's exactly in matlab that dealing with for loops over sub matrices is so annoying due to this
- BeetleB 2y agoIndeed. I was going to point out that mathematicians choose the index based on whatever is convenient for their problem. It could begin at -3, 2, or whatever. I've never heard a mathematician complain that another mathematician is using the "wrong" index. That's something only programmers seem to do.