[Numpy-discussion] Possible bug in np.array type calculation

Charles R Harris charlesr.harris at gmail.com
Tue Apr 3 21:05:22 EDT 2018


On Tue, Apr 3, 2018 at 3:45 PM, Joseph Fox-Rabinovitz <
jfoxrabinovitz at gmail.com> wrote:

> I recently asked a question on Stack Overflow about whether `np.array`
> could raise an error if not passed a dtype parameter:
> https://stackoverflow.com/q/49639414/2988730.
>
> Turns out it can:
>
>     np.array([1, [2]])
>
> raises `ValueError: setting an array element with a sequence.`
> Surprisingly though, the following does not, and gives the expected array
> with `dtype=object`:
>
>     np.array([[1], 2])
>
> Is this behavior a bug of sorts, or is there some arcane reason behind it?
>

It's a bug of sorts, but the creation of object arrays is weird anyway.
There has been a long time semi-proposal to raise an error in these cases
unless `dtype=object` is specified,  and even then there is a question of
where the array ends and the objects begin, nested lists of mixed sized and
such.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20180403/b2fff4fa/attachment.html>


More information about the NumPy-Discussion mailing list