Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Wrong output in take function #9293

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
doelen opened this issue Jun 23, 2017 · 1 comment · Fixed by #13182
Closed

Wrong output in take function #9293

doelen opened this issue Jun 23, 2017 · 1 comment · Fixed by #13182

Comments

@doelen
Copy link

doelen commented Jun 23, 2017

I encountered an error when i use the numpy.take function.
test : 2D array (20000x128) with double values
P: integer vector 128 values in the range of [0...127] none are the same.
if i execute the following code everything works fine and as intended, no error.
np.take(test, P, axis=1, mode='raise', out=test)

if i execute
np.take(test, P, axis=1, mode='wrap', out=test)
my output should be the same as in the other code, since i do not have any out-of-bounds indices. However, the output is different. Values are scrambled and appear multiple times although they are all different.

if executed as test = np.take(test, P, axis=1, mode='wrap') the output is correct.

same for: mode = 'clip'

numpy version 1.12.1
python version 2.7.13

@seberg
Copy link
Member

seberg commented Jun 23, 2017

You are working on the array in place in those two modes, while the raise mode works on a copy (I guess as a trick to be consistent on error, even though there are other corner cases where we can't guarantee this too).

I think this issue is open elsewhere, don't know what the discussion result was there. If you don't want it to be in-place (which will cause this), you need to work on a copy anyway, so using the out keyword has no real use in any case if out is the same as the input (or has overlap with it).

I suppose we could add an overlap guard here, or so, since we started doing that for ufuncs, and a bit other things now.

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

Successfully merging a pull request may close this issue.

2 participants