8000 BUG: Fix apply_along_axis() for when func1d() returns a non-ndarray. by charris · Pull Request #8431 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: Fix apply_along_axis() for when func1d() returns a non-ndarray. #8431

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

Merged
merged 1 commit into from
Dec 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
BUG: Fix apply_along_axis() for when func1d() returns a non-ndarray (#…
…8426)

* BUG: Closes issue #8419

Fixes issue in apply_along_axis() where func1d() returns a non ndarray

* BUG: Fix apply_along_axis() when func1d() returns a non-ndarray

Closes issue #8419. Fixes issue in apply_along_axis() where
func1d() returns a non ndarray by calling asanyarray() on
result. This commit fixes a too long line in the test case.
  • Loading branch information
bennyrowland authored and charris committed Dec 31, 2016
commit cd821332cd4d92643ce77b69ae2286bd4ff7b294
2 changes: 1 addition & 1 deletion numpy/lib/shape_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def apply_along_axis(func1d, axis, arr, *args, **kwargs):
ind[n] = 0
n -= 1
i.put(indlist, ind)
res = func1d(arr[tuple(i.tolist())], *args, **kwargs)
res = asanyarray(func1d(arr[tuple(i.tolist())], *args, **kwargs))
outarr[tuple(i.tolist())] = res
k += 1
if res.shape == ():
Expand Down
6 changes: 6 additions & 0 deletions numpy/lib/tests/test_shape_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ class MinimalSubclass(np.ndarray):
assert isinstance(res, MinimalSubclass)
assert_array_equal(res, np.array([6, 6, 6]).view(MinimalSubclass))

def test_tuple_func1d(self):
def sample_1d(x):
return x[1], x[0]
res = np.apply_along_axis(sample_1d, 1, np.array([[1, 2], [3, 4]]))
assert_array_equal(res, np.array([[2, 1], [4, 3]]))


class TestApplyOverAxes(TestCase):
def test_simple(self):
Expand Down
0