8000 np.asarray throws an error when passed a list containing tuples if the first entry in the list is not a tuple. · Issue #12359 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
np.asarray throws an error when passed a list containing tuples if the first entry in the list is not a tuple. #12359
Closed
@antomaly

Description

@antomaly

Reproducing code example:

import numpy as np
np.asarray(["a",("b","c")])

Error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/numpy/core/numeric.py", line 531, in asarray
    return array(a, dtype, copy=False, order=order)
ValueError: cannot set an array element with a sequence

Note that

np.asarray([("b","c"),"a"])

works fine and gives

array([('b', 'c'), 'a'], dtype=object)

In addition,

np.asarray(["a",("b","c")], dtype="object")

also works and gives

array(['a', ('b', 'c')], dtype=object)

Numpy/Python version information:

('1.12.1', '2.7.13 (default, Nov 24 2017, 17:33:09) \n[GCC 6.3.0 20170516]')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0