Comments (3)
Thanks so much for explaining this in detail, @Ockenfuss and my apologies for taking up your time! I thought the expression would evaluate from left to right. Using np.logical_not()
is a great suggestion.
from xarray.
Thanks for opening your first issue here at xarray! Be sure to follow the issue template!
If you have an idea for a solution, we would really welcome a Pull Request with proposed changes.
See the Contributing Guide for more.
It may take us a while to respond here, but we really value your contribution. Contributors like you help make xarray better.
Thank you!
from xarray.
This is actually expected behaviour in python. If you do ~test.sum(dim="x")
, the call to sum()
has a higher precedence than the bitwise invert operator, represented by ~
. Therefore, test.sum(dim='x')
evaluates to 2
and then ~2
evaluates to -3
. The latter is due to the way integers are represented as bits in python.
In general, it might be better to use np.logical_not(test)
in order to invert the array. logical_not
also works in case your data consists of integers instead of booleans:
import numpy as np
import xarray as xr
data_int=np.array([1, 0, 1, 0])
test_int=xr.DataArray(data_int, coords=dict(x=np.arange(4)))
assert np.logical_not(test_int).sum(dim='x')==2 #works
assert (~test_int).sum(dim='x')==2 #fails
from xarray.
Related Issues (20)
- combine_first() fails when DataArrays are read from netcdf HOT 2
- xr.cftime_range fails when using proleptic_gregorian calendar in cftime.datetime object HOT 2
- When opening a zipped Dataset stored under Zarr on a s3 bucket, `botocore.exceptions.NoCredentialsError: Unable to locate credentials` HOT 2
- netCDF4 indexing: `reindex_like` is very slow if dataset not loaded into memory HOT 4
- Mapping DataTree methods over nodes with variables for which the args are invalid
- ENH: Make `_to_dataframe` faster for extension array columns after `pandas` fix
- `isel(multi_index_level_name = MultiIndex.level)` corrupts the MultiIndex HOT 1
- netCDF encoding and decoding issues. HOT 7
- DataArray .rolling() unclear behaviour when center=False HOT 3
- Dataset constructor always coerces 1D data variables with same name as dim to coordinates HOT 10
- datatree ops.py migration cleanup
- Support concurrent loading of variables HOT 4
- HTML repr for chunked variables with high dimensionality HOT 1
- Example code in the documentation for `Dataset` is not clear HOT 13
- Xarray sponsorship guidelines HOT 3
- Nightly Hypothesis tests failed
- update `to_netcdf` docstring to list support for explicit CDF5 writes HOT 4
- (i)loc slicer specialization for convenient slicing by dimension label as `.loc('dim_name')[:n]`
- Improving performance of open_datatree HOT 4
- Why does xr.apply_ufunc support numpy/dask.arrays?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xarray.