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 boolean indexing not working on Field object #288

Open
skuschel opened this issue Jan 10, 2025 · 0 comments
Open

Numpy boolean indexing not working on Field object #288

skuschel opened this issue Jan 10, 2025 · 0 comments
Labels
enhancement Field core routines affected

Comments

@skuschel
Copy link
Owner

skuschel commented Jan 10, 2025

just noticed that the boolean indexing on Field objects is not working. See https://numpy.org/doc/stable/user/basics.indexing.html
This is generally undesired, because it breaks the regular axes, however capping values beyond a threshold would be good thing, like

import postpic as pp
import numpy as np

f = pp.Field(np.random.random((100, 101)))
f[f<0.5] = 0

currently terminate with an error:

File [~/.venv/py311/lib/python3.11/site-packages/postpic/datahandling.py:2312](http://localhost:8888/home/stephan/.venv/py311/lib/python3.11/site-packages/postpic/datahandling.py#line=2311), in Field._normalize_slices(self, key)
   2310     key = (key,)
   2311 if len(key) != self.dimensions:
-> 2312     raise IndexError("{}D Field requires a {}-tuple of slices as index"
   2313                      "".format(self.dimensions, self.dimensions))
   2315 return tuple(ax._normalize_slice(sl) for ax, sl in zip(self.axes, key))

IndexError: 2D Field requires a 2-tuple of slices as index

postpic version 0.5+58.g315634f

@skuschel skuschel added enhancement Field core routines affected labels Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Field core routines affected
Projects
None yet
Development

No branches or pull requests

1 participant