On Tue, Apr 3, 2018 at 3:45 PM, Joseph Fox-Rabinovitz <
jfoxrabinov...@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
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@python.org
https://mail.python.org/mailman/listinfo/numpy-discussion

Reply via email to