[Numpy-discussion] Fast way to convert (nested) list to numpy object array?

Stephan Hoyer shoyer at gmail.com
Thu Jul 3 13:30:01 EDT 2014


On Thu, Jul 3, 2014 at 5:36 AM, Marc Hulsman <m.hulsman at tudelft.nl> wrote:

> This can however go wrong. Say that we have nested variable length
> lists, what sometimes happens is that part of the data has
> (by chance) only fixed length nested lists, while another part has
> variable length nested lists. If we then unpack, numpy will for
> the first case construct a multi-dimensional array, while for the second
> case it will construct a single-dimensional
> array of nested lists. If we then want to e.g. concatenate this data
> using a generic operation, it will have trouble to handle the mix of
> multi-dimensional and 1-dimensional arrays.  The code becomes quite a
> bit simpler if I know at forehand that I can expect just e.g.
> a 1-dimensional array.
>

Pandas has a couple of awkward work-arounds to do just that (creating
object arrays). Might be worth taking a look:
https://github.com/pydata/pandas/blob/master/pandas/lib.pyx#L315
https://github.com/pydata/pandas/blob/master/pandas/core/common.py#L2124

Cheers,
Stephan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140703/7072f255/attachment.html>


More information about the NumPy-Discussion mailing list