I’ve learned the theory in a computer science class about multi dimensional arrays & records of arrays but I am unsure of how to implement this in Python. I was thinking of using an array of records as it would allow me to have different data types in the one record but at the same time I was thinking that a multi dimensional array would also be good to learn in Python.
I’ve Googled around a bit & I have found numpy but I’m not sure which function in numpy I’d use. I saw one with tuples but I wasn’t keen on using that as tuples can’t be modified.
I’m using Python 3.2 but I don’t mind using Python 2.7 either.
Depends how you want to interact with them. Consider using Numpy. Specifically, have a look at the N-Dimensional array. It provides a rich API for manipulation and comparison.
If numpy feels like overkill, you can implement a multi-array using simple tuples/lists.
As an example, to convert
multi_arrayinto a numpyndarray:Notice that ndarray expects as it’s first argument a
shape. This means you need to know the dimensions of the array before you create it. Changing the dimensions of the ndarray is known as ‘reshaping’.