[Numpy-discussion] np.array creation: unexpected behaviour
Emanuele Olivetti
emanuele at relativita.com
Fri Jan 24 11:30:33 EST 2014
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?
Best,
Emanuele
More information about the NumPy-Discussion
mailing list