|
|
|
|
|
by princeb
3311 days ago
|
|
yeah i think maybe numericals aren't the best example since the initial value is always labeled x_0 and if you want to create a 2d array with the first array your X_0s then creating an N + 1 array makes sense. your matrix example is totally bizarre though. the top left of a matrix A is always A_(1,1). so not sure what a[0,0] means. a 1x1 matrix is always 1 element, which is a[1,1]. the number of elements in a mxn array is m*n. |
|
In maths notation it usually is, yes, but in a zero-based language it's usually a[0, 0] (and I've seen maths and CS papers where it's 0, too). The number of elements in a mxn array is still m*n, but the indices don't go that high. For example, in Python you'd loop through m rows with "for i in range(m)", which will go from 0 to m-1 (actually, you might do "for row in a" and not bother with indices). You hardly ever need to do m-1 manually - if you want the last row it's just a[-1, :].
I'm not saying zero-based is always better, but I haven't seen many situations where one-based is preferable.