You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
atoms.positions returns a view to the underlying array. This means code like u.atoms[:n].positions[:] = np.ones((n,3)) does an inplace update of the coordinates.
Actual behavior
atoms.positions returns a copy. This is especially true if only a selection of atoms in the universe is used.
I know this a limitation of numpy when indexing. I'm also aware that my code example is not how one would ideally write the code. However, this is still potentially confusing behavior and I think we get questions about this on the mailing list once in a while.
I also do not know a good solution to this problem. Or even if there is one using numpy. It would still be nice to have this in a Common Pitfalls section of the documentation. (Maybe this is already there and I just don't know?)
It is definitely possible to write our own array structure in C that supports to create views to individual atoms. I don't think the effort this would involve is worth it though.
Currently version of MDAnalysis
Which version are you using? (run python -c "import MDAnalysis as mda; print(mda.__version__)")
0.18.0
Which version of Python (python -V)?
3.6
Which operating system?
Arch Linux
The text was updated successfully, but these errors were encountered:
Expected behavior
atoms.positions
returns a view to the underlying array. This means code likeu.atoms[:n].positions[:] = np.ones((n,3))
does an inplace update of the coordinates.Actual behavior
atoms.positions
returns a copy. This is especially true if only a selection of atoms in the universe is used.Code to reproduce the behavior
Comments
I know this a limitation of numpy when indexing. I'm also aware that my code example is not how one would ideally write the code. However, this is still potentially confusing behavior and I think we get questions about this on the mailing list once in a while.
I also do not know a good solution to this problem. Or even if there is one using numpy. It would still be nice to have this in a
Common Pitfalls
section of the documentation. (Maybe this is already there and I just don't know?)It is definitely possible to write our own array structure in C that supports to create views to individual atoms. I don't think the effort this would involve is worth it though.
Currently version of MDAnalysis
python -c "import MDAnalysis as mda; print(mda.__version__)"
)0.18.0
python -V
)?3.6
Arch Linux
The text was updated successfully, but these errors were encountered: