[Numpy-discussion] converting a list of tuples into an array of tuples?

Stephan Hoyer shoyer at gmail.com
Mon Feb 9 12:39:13 EST 2015


It appears that the only reliable way to do this may be to use a loop to
modify an object arrays in-place. Pandas has a version of this written in
Cython:
https://github.com/pydata/pandas/blob/c1a0dbc4c0dd79d77b2a34be5bc35493279013ab/pandas/lib.pyx#L342

To quote Wes McKinney "Seriously can't believe I had to write this function"

Best,
Stephan

On Mon, Feb 9, 2015 at 8:31 AM, Benjamin Root <ben.root at ou.edu> wrote:

> I am trying to write up some code that takes advantage of np.tile() on
> arbitrary array-like objects. I only want to tile along the first axis. Any
> other axis, if they exist, should be left alone. I first coerce the object
> using np.asanyarray(), tile it, and then coerce it back to the original
> type.
>
> The problem seems to be that some of my array-like objects are being
> "over-coerced", particularly the list of tuples. I tried doing
> "np.asanyarray(a, dtype='O')", but that still turns it into a 2-D array.
>
> Am I missing something?
>
> Thanks,
> Ben Root
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150209/4047b7d4/attachment.html>


More information about the NumPy-Discussion mailing list