[melbourne-pug] Lists or Arrays - When do I use what and why - Or : Confused much? I am, Now

Richard Jones r1chardj0n3s at gmail.com
Mon Feb 7 03:44:51 CET 2011


On Mon, Feb 7, 2011 at 1:15 PM, David Crisp <dcrisp at netspace.net.au> wrote:
> I need a little bit of assistance understanding when to use python arrays
> from scipy and when to use the lists.   In part,  my confusion comes about
> from my use of arrays in C, Visual Basic, and perl.

Python arrays (http://docs.python.org/library/array.html and the basic
ones found in numpy) are almost identical to C arrays - you declare
them to contain a fixed amount of data of a certain type. Very
memory-efficient.

Python lists are resizable arrays that contain data of any type (it's
an array of pointers to PyObject). IIRC they are allocated using a 2x
expansion algorithm and really are not memory-efficient if you just
want to store a bunch of floats or ints (or ubytes!)

You could probably do something with arrays for the i, r, g and b
values in a nested list of lists. And sort into your quantised bins
when you read the data in, rather than quantise between in-memory
structures.

The scipy/numpy community have been dealing with these problems for a
while (using sparse arrays, submatrices, ...) and your best bet is to
ask in that community for further help
(http://www.scipy.org/Mailing_Lists).


     Richard


More information about the melbourne-pug mailing list