[Numpy-discussion] Creating array containing empty lists
Stéfan van der Walt
stefan at sun.ac.za
Wed Mar 25 07:43:03 EDT 2009
2009/3/25 Jesper Larsen <jesper.webmail at gmail.com>:
> import numpy as npy
> a = npy.empty((2), dtype=npy.object_)
>
> # Works fine:
> for i in range(len(a)):
> a[i] = []
> print a
>
> # Does not work:
> a[:] = []
> a[:] = list()
Slightly simpler would be:
In [26]: x = np.empty((2,), dtype=object)
In [27]: x[:] = [[] * len(x)]
Stéfan
More information about the NumPy-Discussion
mailing list