4 ms·
> 0 based is due to programming iteration. I think it makes sense for enumeration in general to begin at 0. It's a mapping from the natural numbers after all,
by Bromskloss 9y ago
> 0 based is due to programming iteration.
I think it makes sense for enumeration in general to begin at 0. It's a mapping from the natural numbers after all, and zero is the most natural number!
What makes you think of programming iteration as a motivation for zero-based indexing?
- baldfat 9y ago> To quote wikipedia on Zero-based "Zero-based numbering or index origin = 0[1][2] is a way of numbering in which the initial element of a sequence is assigned the index 0, rather than the index 1 as is typical in everyday non-mathematical/non-programming circumstances." 1 Based 0 = 1 1 = 2 Zero based 0 = nothing 1 = 1 Seem important for mathematics.
- baldfat 9y agoAlso head and tail in Pandas is 1 based! That drove me crazy. print(users[users.age > 25].head(3)) Returns 3 elements and not 4!
- Bromskloss 9y agoIs it possible that the argument to `head` is the _number_ of elements to return, and that the choice of indexing therefore doesn't enter the picture?
- Bromskloss 9y agoActually, even if the argument (3 in this case) were an index, I would expect it to be the index of the first element _not_ to fetch, like how intervals typically are written with an inclusive lower bound and an exclusive upper bound as in "2 ≤ i < 13" [0]. That would make the result you're getting consistent with zero-indexing, but not with one-indexing. Of course, I don't know what Pandas is like outside this particular example, or what Pandas even is. A database thing? [0] https://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF https://www.cs.utexas.edu/users/EWD/ewd08xx/EWD831.PDF
- goatlover 9y agoI start counting at 1 for everything when not programming, so I don't understand this. I always understood zero-based indexing to be primarily a hardware driven concern, with C being fairly close to assembly, and so many languages ended up copying C's syntax.
- dnautics 9y agoEnumeration should generally begin at 1. In common language, you don't say "this person won the 0th place trophy", you say "this person won the 1st place trophy". It's address offsetting that should begin at 0. C strongly encourages you to think of arrays as simply address+offset pointers, so it absolutely should start with 0.
- Bromskloss 9y ago> you don't say "this person won the 0th place trophy" I think it would make sense to say it. The reason I don't is that people around me would misunderstand me if I did. (Around some people, it works, though!)
- goatlover 9y agoIf some told me they got the "0th place trophy", I would take that to be a colorful way of saying they didn't win anything, as 0 means nothing, or the absence of trophies, in this case.
- Bromskloss 9y agoThat's just an artefact of being used to a certain way, isn't it? For me, it's about finding fundamental reasons for one convention or another, not about the practicalities.
- goatlover 9y agoThe reason for not starting at zero for enumeration is that zero means a lack of things to count or list. Therefore, we should start with the one, since that's the first number where we would have reason to enumerate.
- dnautics 9y agoWhy not say someone won the -1th place trophy? Where does it start?