Use Python idioms common to Python 2 and 3
Fix Numpy errors concerning array indexing