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

numpy.array inplace exchange duplicates/overwrites elements (Trac #1057) #1655

Closed
thouis opened this issue Oct 19, 2012 · 2 comments
Closed
Labels

Comments

@thouis
Copy link
Contributor

thouis commented Oct 19, 2012

Original ticket http://projects.scipy.org/numpy/ticket/1057 on 2009-03-18 by trac user praeteri, assigned to unknown.

simply check this:

In [1]: from numpy import array

In [2]: a = array([ array([1,1]), array([2,2]), array([3,3]), array([4,4]), array([5,5]) ]) 

In [3]: a[0], a[1] = a[1], a[0]

In [4]: a
Out[4]: 
array([[2, 2],
       [2, 2],
       [3, 3],
       [4, 4],
       [5, 5]])

This data format is used e.g. by pylab.load.
The inplace exchange e.g. by random.shuffle.
Hence, it is a very common situation...

I don't know if this is the way it should be.

@thouis
Copy link
Contributor Author

thouis commented Oct 19, 2012

@charris wrote on 2009-03-18

It is the difference between objects and views. The views a[0], a[1] reference rows in a and the assignment a[0] = a[1] copies the data from row 1 to row 0. If the rows were themselves objects then things would work in the normal python way, but they aren't. So I think the current behaviour is correct and if the other behaviour is assumed in some applications then it is a bug.

@thouis
Copy link
Contributor Author

thouis commented Oct 19, 2012

@pv wrote on 2009-07-13

I don't think we can do much about this, except to document it. The items on the RHS never know they are being assigned to the same array.

@thouis thouis closed this as completed Oct 19, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant