Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 805370b

Browse files
authored
Merge pull request #12070 from anntzer/isscalar
Avoid some uses of np.isscalar.
2 parents 7fe3dd2 + 9199392 commit 805370b

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

examples/lines_bars_and_markers/filled_step.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ def filled_hist(ax, edges, values, bottoms=None, orientation='v',
6161
lb=len(edges), lv=len(values)))
6262

6363
if bottoms is None:
64-
bottoms = np.zeros_like(values)
65-
if np.isscalar(bottoms):
66-
bottoms = np.ones_like(values) * bottoms
64+
bottoms = 0
65+
bottoms = np.broadcast_to(bottoms, values.shape)
6766

6867
values = np.r_[values, values[-1]]
6968
bottoms = np.r_[bottoms, bottoms[-1]]

lib/matplotlib/streamplot.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -356,15 +356,12 @@ class StreamMask(object):
356356
"""
357357

358358
def __init__(self, density):
359-
if np.isscalar(density):
360-
if density <= 0:
361-
raise ValueError("If a scalar, 'density' must be positive")
362-
self.nx = self.ny = int(30 * density)
363-
else:
364-
if len(density) != 2:
365-
raise ValueError("'density' can have at maximum 2 dimensions")
366-
self.nx = int(30 * density[0])
367-
self.ny = int(30 * density[1])
359+
try:
360+
self.nx, self.ny = (30 * np.broadcast_to(density, 2)).astype(int)
361+
except ValueError:
362+
raise ValueError("'density' must be a scalar or be of length 2")
363+
if self.nx < 0 or self.ny < 0:
364+
raise ValueError("'density' must be positive")
368365
self._mask = np.zeros((self.ny, self.nx))
369366
self.shape = self._mask.shape
370367

0 commit comments

Comments
 (0)