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

Array view instead of copy #328

Open
WenzDaniel opened this issue Oct 13, 2020 · 0 comments
Open

Array view instead of copy #328

WenzDaniel opened this issue Oct 13, 2020 · 0 comments
Labels
bug Something isn't working documentation Something should be addressed in the docs wontfix This will not be worked on

Comments

@WenzDaniel
Copy link
Collaborator

Users should be aware that lines like the following:

for d in data_type:
    data= d['data'][:d['length']]
    modifies_data(data)

will create only a "view" onto data in memory. Hence when data is modified by any function, e.g. modifies_data, data_type['data']will be modified as well. This behavior is in many cases not desired and leads to bugs which are really hard to trace. The correct way looks like:

for d in data_type:
    data = np.copy(d['data'][:d['length']])
    modifies_data(data)

See also https://stackoverflow.com/questions/11524664/how-can-i-tell-if-numpy-creates-a-view-or-a-copy and https://stackoverflow.com/questions/4370745/view-onto-a-numpy-array for some additional information.

@WenzDaniel WenzDaniel added bug Something isn't working documentation Something should be addressed in the docs labels Oct 13, 2020
@JoranAngevaare JoranAngevaare added the wontfix This will not be worked on label Feb 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Something should be addressed in the docs wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants