8000 IndexError on apply_along_axis with empty 2D array · Issue #7454 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

IndexError on apply_along_axis with empty 2D array #7454

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

Closed
Wilfred opened this issue Mar 23, 2016 · 3 comments
Closed

IndexError on apply_along_axis with empty 2D array #7454

Wilfred opened this issue Mar 23, 2016 · 3 comments

Comments

@Wilfred
Copy link
Wilfred commented Mar 23, 2016
In [21]: a = np.empty(shape=(0,0))

In [22]: np.lib.apply_along_axis(sum, 1, a)
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-22-2fcce4e707fd> in <module>()
----> 1 np.lib.apply_along_axis(sum, 1, a)

myvirtualenv/lib/python2.7/site-packages/numpy-1.9.2-py2.7-linux-x86_64.egg/numpy/lib/shape_base.pyc in apply_along_axis(func1d, axis, arr, *args, **kwargs)
     89     outshape = asarray(arr.shape).take(indlist)
     90     i.put(indlist, ind)
---> 91     res = func1d(arr[tuple(i.tolist())], *args, **kwargs)
     92     #  if res is a number, then we have a smaller output array
     93     if isscalar(res):

IndexError: index 0 is out of bounds for axis 0 with size 0
@eric-wieser
Copy link
Member
eric-wieser commented Feb 13, 2017

What do you think the correct behaviour here is? It's impossible to know what dtype of value to return without invoking the function. So should we invoke the function on an array of garbage?

As of #8441, this now raises StopIteration instead, which is even worse, as it could cause silent failures in iterator

@Wilfred
Copy link
Author
Wilfred commented Feb 13, 2017

I was going to suggest asserting that the array was non-empty, but I see #8614 is raising ValueError which seems like a clean solution to me.

I think I bumped into this when testing boundary cases in code that wraps apply_along_axis.

@eric-wieser
Copy link
Member

Also, this duplicates #6927

@mhvk mhvk closed this as completed in 61640a8 Feb 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0