Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 114010d

Browse filesBrowse files
authored
Merge pull request #13384 from anntzer/uncompress
Replace np.compress by boolean indexing.
2 parents 52f1ac4 + d3cd57a commit 114010d
Copy full SHA for 114010d

File tree

Expand file treeCollapse file tree

6 files changed

+19
-21
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+19
-21
lines changed

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+10-12Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5891,23 +5891,21 @@ def pcolor(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
58915891
# don't plot if C or any of the surrounding vertices are masked.
58925892
mask = ma.getmaskarray(C) + xymask
58935893

5894-
compress = np.compress
5895-
5896-
ravelmask = (mask == 0).ravel()
5897-
X1 = compress(ravelmask, ma.filled(X[:-1, :-1]).ravel())
5898-
Y1 = compress(ravelmask, ma.filled(Y[:-1, :-1]).ravel())
5899-
X2 = compress(ravelmask, ma.filled(X[1:, :-1]).ravel())
5900-
Y2 = compress(ravelmask, ma.filled(Y[1:, :-1]).ravel())
5901-
X3 = compress(ravelmask, ma.filled(X[1:, 1:]).ravel())
5902-
Y3 = compress(ravelmask, ma.filled(Y[1:, 1:]).ravel())
5903-
X4 = compress(ravelmask, ma.filled(X[:-1, 1:]).ravel())
5904-
Y4 = compress(ravelmask, ma.filled(Y[:-1, 1:]).ravel())
5894+
unmask = ~mask
5895+
X1 = ma.filled(X[:-1, :-1])[unmask]
5896+
Y1 = ma.filled(Y[:-1, :-1])[unmask]
5897+
X2 = ma.filled(X[1:, :-1])[unmask]
5898+
Y2 = ma.filled(Y[1:, :-1])[unmask]
5899+
X3 = ma.filled(X[1:, 1:])[unmask]
5900+
Y3 = ma.filled(Y[1:, 1:])[unmask]
5901+
X4 = ma.filled(X[:-1, 1:])[unmask]
5902+
Y4 = ma.filled(Y[:-1, 1:])[unmask]
59055903
npoly = len(X1)
59065904

59075905
xy = np.stack([X1, Y1, X2, Y2, X3, Y3, X4, Y4, X1, Y1], axis=-1)
59085906
verts = xy.reshape((npoly, 5, 2))
59095907

5910-
C = compress(ravelmask, ma.filled(C[0:Ny - 1, 0:Nx - 1]).ravel())
5908+
C = ma.filled(C[:Ny - 1, :Nx - 1])[unmask]
59115909

59125910
linewidths = (0.25,)
59135911
if 'linewidth' in kwargs:

‎lib/matplotlib/cbook/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/cbook/__init__.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,23 +1311,23 @@ def _compute_conf_interval(data, med, iqr, bootstrap):
13111311
hival = np.percentile(x, whis[1])
13121312

13131313
# get high extreme
1314-
wiskhi = np.compress(x <= hival, x)
1314+
wiskhi = x[x <= hival]
13151315
if len(wiskhi) == 0 or np.max(wiskhi) < q3:
13161316
stats['whishi'] = q3
13171317
else:
13181318
stats['whishi'] = np.max(wiskhi)
13191319

13201320
# get low extreme
1321-
wisklo = np.compress(x >= loval, x)
1321+
wisklo = x[x >= loval]
13221322
if len(wisklo) == 0 or np.min(wisklo) > q1:
13231323
stats['whislo'] = q1
13241324
else:
13251325
stats['whislo'] = np.min(wisklo)
13261326

13271327
# compute a single array of outliers
13281328
stats['fliers'] = np.hstack([
1329-
np.compress(x < stats['whislo'], x),
1330-
np.compress(x > stats['whishi'], x)
1329+
x[x < stats['whislo']],
1330+
x[x > stats['whishi']],
13311331
])
13321332

13331333
# add in the remaining stats

‎lib/matplotlib/ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/ticker.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,9 +2647,9 @@ def __call__(self):
26472647
mod = np.abs((locs - t0) % majorstep)
26482648
cond1 = mod > minorstep / 10.0
26492649
cond2 = ~np.isclose(mod, majorstep, atol=0)
2650-
locs = locs.compress(cond1 & cond2)
2650+
locs = locs[cond1 & cond2]
26512651

2652-
return self.raise_if_exceeds(np.array(locs))
2652+
return self.raise_if_exceeds(locs)
26532653

26542654
def tick_values(self, vmin, vmax):
26552655
raise NotImplementedError('Cannot get tick locations for a '

‎lib/matplotlib/tri/triangulation.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tri/triangulation.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def get_masked_triangles(self):
117117
Return an array of triangles that are not masked.
118118
"""
119119
if self.mask is not None:
120-
return self.triangles.compress(1 - self.mask, axis=0)
120+
return self.triangles[~self.mask]
121121
else:
122122
return self.triangles
123123

‎lib/matplotlib/tri/tripcolor.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tri/tripcolor.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def tripcolor(ax, *args, alpha=1.0, norm=None, cmap=None, vmin=None,
112112
C = C[maskedTris].mean(axis=1)
113113
elif tri.mask is not None:
114114
# Remove color values of masked triangles.
115-
C = C.compress(1-tri.mask)
115+
C = C[~tri.mask]
116116

117117
collection = PolyCollection(verts, **kwargs)
118118

‎lib/matplotlib/tri/tritools.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tri/tritools.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def _total_to_compress_renum(mask, n=None):
292292
n = np.size(mask)
293293
if mask is not None:
294294
renum = np.full(n, -1, dtype=np.int32) # Default num is -1
295-
valid = np.arange(n, dtype=np.int32).compress(~mask, axis=0)
295+
valid = np.arange(n, dtype=np.int32)[~mask]
296296
renum[valid] = np.arange(np.size(valid, 0), dtype=np.int32)
297297
return renum
298298
else:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.