[Numpy-discussion] Dynamic array list implementation

Nicolas P. Rougier Nicolas.Rougier at inria.fr
Tue Dec 22 06:47:12 EST 2015


I've coded a typed dynamic list based on numpy array (needed for the glumpy project).
Code is available from https://github.com/rougier/numpy-list


A Numpy array list is a strongly typed list whose type can be anything that can be interpreted as a numpy data type.

>>> L = ArrayList( [[0], [1,2], [3,4,5], [6,7,8,9]] )
>>> print(L)
[[0], [1 2], [3 4 5], [6 7 8 9]]
>>> print(L.data)
[0 1 2 3 4 5 6 7 8 9]
You can add several items at once by specifying common or individual size: a single scalar means all items are the same size while a list of sizes is used to specify individual item sizes.

>>> L = ArrayList( np.arange(10), [3,3,4])
>>> print(L)
[[0 1 2], [3 4 5], [6 7 8 9]]
>>> print(L.data)
[0 1 2 3 4 5 6 7 8 9]
You can also us typed list for storing strings with different sizes:

>>> L = ArrayList(["Hello", "world", "!"])
>>> print(L[0])
'Hello'
>>> L[1] = "brave new world"
>>> print(L)
['Hello', 'brave new world', '!']


Nicolas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20151222/4a7746e9/attachment.html>


More information about the NumPy-Discussion mailing list