Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

np.asanyarray inconsistent behavior for tuple/array of arrays #8330

Closed
adambielski opened this issue Nov 29, 2016 · 2 comments
Closed

np.asanyarray inconsistent behavior for tuple/array of arrays #8330

adambielski opened this issue Nov 29, 2016 · 2 comments

Comments

@adambielski
Copy link

When passing tuple of ndarrays to np.asanyarray, it may return array of arrays OR give ValueError when first dimensions of arrays match. Found out trying to np.save a tuple (sometimes worked, sometimes did not).

np.__version__
'1.11.2'

a = np.ones((2,1))
b = np.ones(3)
np.asanyarray((a,b))
array([array([[ 1.],
       [ 1.]]), array([ 1.,  1.,  1.])], dtype=object)

b = b[:-1] # now the first dimensions match
np.asanyarray((a,b))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ml/anaconda/envs/face_lasagne/lib/python2.7/site-packages/numpy/core/numeric.py", line 533, in asanyarray
    return array(a, dtype, copy=False, order=order, subok=True)
ValueError: could not broadcast input array from shape (2,1) into shape (2)
@charris
Copy link
Member

charris commented Dec 3, 2016

Yep, looks like a bug in np.array.

@eric-wieser
Copy link
Member

Closing as a duplicate of #7453

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants