As discussed earlier on the post on 'Circular Indexing', considering 
interpreting indices that lie outside the range 0 to n-1 modulo n for list 
indexing. Thus element n corresponds to element 0, n+1 to element 1 and so on. 
This has two consequences:


1.) Makes the Python convention of interpreting index -1 as the last element 
more logical since -1 is the same as n-1 when taken modulo n. If -1 is the 
first element then to be logically consistent we have to interpret index n as 
the element 0 as well!


Obviously this does allow certain errors to slip but if you are going to allow 
an index of -1 (indices that occur before 0) then you might just as well allow 
indices above n-1 to be logically consistent.


2.) If circular indexing is used then instead of using a double FOR loop to go 
through a loop twice we can iterate from 0 to 2n !


Although trivial for the case of one dimensional lists/arrays, cylindrical 
indexing (for 2D arrays) and toroidal  indexing (2D, 3D and nD arrays) schemes 
might be worth exploring for n-dimensional NumPy arrays.


Circular and in general cylindrical or toroidal indexing schemes might simplify 
coding by reducing the number of FOR loops when iterating over nD arrays in 
NumPy.

_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/A5D6P2G26NYMZAV4WZGFTWYDI5UA25KZ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to