On Fri, Jan 24, 2014 at 11:30 AM, Emanuele Olivetti
<emanu...@relativita.com> wrote:
> Hi,
>
> I just came across this unexpected behaviour when creating
> a np.array() from two other np.arrays of different shape.
> Have a look at this example:
> ----
> import numpy as np
> a = np.zeros(3)
> b = np.zeros((2,3))
> c = np.zeros((3,2))
> ab = np.array([a, b])
> print ab.shape, ab.dtype
> ac = np.array([a, c], dtype=np.object)
> print ac.shape, ac.dtype
> ac_no_dtype = np.array([a, c])
> print ac_no_dtype.shape, ac_no_dtype.dtype
> ----
> The output, with NumPy v1.6.1 (Ubuntu 12.04) is:
> ----
> (2,) object
> (2, 3) object
> Traceback (most recent call last):
>    File "/tmp/numpy_bug.py", line 9, in <module>
>      ac_no_dtype = np.array([a, c])
> ValueError: setting an array element with a sequence.
> ----
>
> The result for 'ab' is what I expect. The one for 'ac' is
> a bit surprising. The one for ac_no_dtype even
> is more surprising.
>
> Is this an expected behaviour?

the exception in ac_no_dtype is what I always expected, since it's not
a rectangular array. It usually happened when I make a mistake.
**Unfortunately** in newer numpy version it will also create an object array.

AFAIR

Josef

>
> Best,
>
> Emanuele
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to