Numpy masked operations failing due to comparison functions for __eq__
#822
Unanswered
scottstanie
asked this question in
Q&A
Replies: 1 comment 1 reply
-
|
well if you do |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Using the
Reader's.readmethod on a geotiff gives backImageData. I expected to be able to runnp.nansumon it, but I getValueError: The truth value of an array with more than one element is ambiguous..Running
np.sumworks fine.Reproducing script:
Traceback
File ~/.cache/uv/archive-v0/0bGl3mVbNZ8ByG2ZVow-P/lib/python3.13/site-packages/numpy/lib/_nanfunctions_impl.py:726, in nansum(a, axis, dtype, out, keepdims, initial, where) 634 @array_function_dispatch(_nansum_dispatcher) 635 def nansum(a, axis=None, dtype=None, out=None, keepdims=np._NoValue, 636 initial=np._NoValue, where=np._NoValue): 637 """ 638 Return the sum of array elements over a given axis treating Not a 639 Numbers (NaNs) as zero. (...) 724 725 """ --> 726 a, mask = _replace_nan(a, 0) 727 return np.sum(a, axis=axis, dtype=dtype, out=out, keepdims=keepdims, 728 initial=initial, where=where) File ~/.cache/uv/archive-v0/0bGl3mVbNZ8ByG2ZVow-P/lib/python3.13/site-packages/numpy/lib/_nanfunctions_impl.py:102, in _replace_nan(a, val) 98 a = np.asanyarray(a) 100 if a.dtype == np.object_: 101 # object arrays do not support `isnan` (gh-9009), so make a guess --> 102 mask = np.not_equal(a, a, dtype=bool) 103 elif issubclass(a.dtype.type, np.inexact): 104 mask = np.isnan(a) File ~/.cache/uv/archive-v0/0bGl3mVbNZ8ByG2ZVow-P/lib/python3.13/site-packages/attr/_make.py:1647, in __ne__(self, other) 1642 def __ne__(self, other): 1643 """ 1644 Check equality and either forward a NotImplemented or 1645 return the result negated. 1646 """ -> 1647 result = self.__eq__(other) 1648 if result is NotImplemented: 1649 return NotImplemented File <attrs generated methods rio_tiler.models.ImageData>:20, in __eq__(self, other) 17 if other.__class__ is not self.__class__: 18 return NotImplemented 19 return ( ---> 20 self.array == other.array and 21 self.assets == other.assets and 22 self.bounds == other.bounds and 23 self.crs == other.crs and 24 self.metadata == other.metadata and 25 self.band_names == other.band_names and 26 self.dataset_statistics == other.dataset_statistics and 27 self.cutline_mask == other.cutline_mask 28 ) ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()Beta Was this translation helpful? Give feedback.
All reactions