Skip to content

Commit

Permalink
force tuple(slicer) for ndarray slicing
Browse files Browse the repository at this point in the history
It seems that newer versions (1.23.1) of numpy is forcing tuple slicers.

ipart/AR_detector.py:
    padmask[slice(pad,-pad), slice(pad,-pad)] changed to
    padmask[tuple(slice(pad,-pad), slice(pad,-pad))]

ipart/utils.funcs.py:
    newdata=self.data[slicer] ->
    newdata=self.data[tuple(slicer)]
  • Loading branch information
Xunius committed Aug 16, 2022
1 parent fb5f99e commit 8b4d186
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ipart/AR_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,7 @@ def paddedClosing(mask, ele, pad, has_cv):
else:
padmask=morphology.closing(padmask, selem=ele)
# trim
padmask=padmask[slice(pad,-pad), slice(pad,-pad)]
padmask=padmask[tuple(slice(pad,-pad), slice(pad,-pad))]
return padmask

if thres_low is None:
Expand Down
6 changes: 3 additions & 3 deletions ipart/utils/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def sliceIndex(self,idx1,idx2,axis=0,squeeze=True):
#--------------------Slice data--------------------
slicer=[slice(None),]*self.ndim
slicer[axis]=slice(idx1,idx2)
newdata=self.data[slicer]
newdata=self.data[tuple(slicer)]
if idx2-idx1==1 and squeeze:
newdata=np.squeeze(newdata, axis=axis)

Expand Down Expand Up @@ -347,7 +347,7 @@ def sliceData(self, v1, v2, axis=0):
else:
raise Exception("No data found in [v1,v2].")

newdata=self.data[slicer] # if var is np.ndarray
newdata=self.data[tuple(slicer)] # if var is np.ndarray

#--------------Create a new data obj--------------
newaxisdata=axisdata[idx]
Expand Down Expand Up @@ -1037,7 +1037,7 @@ def getSlab(var, index1=-1, index2=-2, verbose=True):
slicer=['0',]*ndim
slicer[index1]=':'
slicer[index2]=':'
string='slab=var[%s]' %','.join(slicer)
string='slab=var[tuple(%s)]' %','.join(slicer)
exec(string)
return slab

Expand Down

0 comments on commit 8b4d186

Please sign in to comment.