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

Skip to content

Commit 3040b90

Browse files
authored
Merge pull request #13383 from anntzer/untake
Replace np.take by normal indexing.
2 parents e624d6a + a8ed02b commit 3040b90

File tree

5 files changed

+22
-26
lines changed

5 files changed

+22
-26
lines changed

examples/event_handling/pick_event_demo.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def onpick1(event):
9393
xdata = thisline.get_xdata()
9494
ydata = thisline.get_ydata()
9595
ind = event.ind
96-
print('onpick1 line:', zip(np.take(xdata, ind), np.take(ydata, ind)))
96+
print('onpick1 line:', np.column_stack([xdata[ind], ydata[ind]]))
9797
elif isinstance(event.artist, Rectangle):
9898
patch = event.artist
9999
print('onpick1 patch:', patch.get_path())
@@ -129,10 +129,10 @@ def line_picker(line, mouseevent):
129129
d = np.sqrt(
130130
(xdata - mouseevent.xdata)**2 + (ydata - mouseevent.ydata)**2)
131131

132-
ind = np.nonzero(np.less_equal(d, maxd))
132+
ind, = np.nonzero(d <= maxd)
133133
if len(ind):
134-
pickx = np.take(xdata, ind)
135-
picky = np.take(ydata, ind)
134+
pickx = xdata[ind]
135+
picky = ydata[ind]
136136
props = dict(ind=ind, pickx=pickx, picky=picky)
137137
return True, props
138138
else:
@@ -154,7 +154,7 @@ def pick_scatter_plot():
154154

155155
def onpick3(event):
156156
ind = event.ind
157-
print('onpick3 scatter:', ind, np.take(x, ind), np.take(y, ind))
157+
print('onpick3 scatter:', ind, x[ind], y[ind])
158158

159159
fig, ax = plt.subplots()
160160
col = ax.scatter(x, y, 100*s, c, picker=True)

lib/matplotlib/cbook/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ def delete_masked_points(*args):
10631063
if len(igood) < nrecs:
10641064
for i, x in enumerate(margs):
10651065
if seqlist[i]:
1066-
margs[i] = x.take(igood, axis=0)
1066+
margs[i] = x[igood]
10671067
for i, x in enumerate(margs):
10681068
if seqlist[i] and isinstance(x, np.ma.MaskedArray):
10691069
margs[i] = x.filled()

lib/matplotlib/colorbar.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -741,13 +741,11 @@ def _outline(self, X, Y):
741741
'''
742742
N = X.shape[0]
743743
ii = [0, 1, N - 2, N - 1, 2 * N - 1, 2 * N - 2, N + 1, N, 0]
744-
x = np.take(np.ravel(np.transpose(X)), ii)
745-
y = np.take(np.ravel(np.transpose(Y)), ii)
746-
x = x.reshape((len(x), 1))
747-
y = y.reshape((len(y), 1))
748-
if self.orientation == 'horizontal':
749-
return np.hstack((y, x))
750-
return np.hstack((x, y))
744+
x = X.T.reshape(-1)[ii]
745+
y = Y.T.reshape(-1)[ii]
746+
return (np.column_stack([y, x])
747+
if self.orientation == 'horizontal' else
748+
np.column_stack([x, y]))
751749

752750
def _edges(self, X, Y):
753751
'''
@@ -1121,10 +1119,10 @@ def _locate(self, x):
11211119
i0[ibot] += 1
11221120
ii[ibot] += 1
11231121

1124-
db = np.take(b, ii) - np.take(b, i0)
11251122
y = self._y
1126-
dy = np.take(y, ii) - np.take(y, i0)
1127-
z = np.take(y, i0) + (xn - np.take(b, i0)) * dy / db
1123+
db = b[ii] - b[i0]
1124+
dy = y[ii] - y[i0]
1125+
z = y[i0] + (xn - b[i0]) * dy / db
11281126
return z
11291127

11301128
def set_alpha(self, alpha):

lib/matplotlib/quiver.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,11 @@ def _h_arrows(self, length):
702702
minsh - self.headlength, minsh], np.float64)
703703
y0 = 0.5 * np.array([1, 1, self.headwidth, 0], np.float64)
704704
ii = [0, 1, 2, 3, 2, 1, 0, 0]
705-
X = x.take(ii, 1)
706-
Y = y.take(ii, 1)
705+
X = x[:, ii]
706+
Y = y[:, ii]
707707
Y[:, 3:-1] *= -1
708-
X0 = x0.take(ii)
709-
Y0 = y0.take(ii)
708+
X0 = x0[ii]
709+
Y0 = y0[ii]
710710
Y0[3:-1] *= -1
711711
shrink = length / minsh if minsh != 0. else 0.
712712
X0 = shrink * X0[np.newaxis, :]

lib/matplotlib/tests/test_cbook.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,21 @@ def test_bad_first_arg(self):
4747
def test_string_seq(self):
4848
actual = dmp(self.arr_s, self.arr1)
4949
ind = [0, 1, 2, 5]
50-
expected = (self.arr_s2.take(ind), self.arr2.take(ind))
50+
expected = (self.arr_s2[ind], self.arr2[ind])
5151
assert_array_equal(actual[0], expected[0])
5252
assert_array_equal(actual[1], expected[1])
5353

5454
def test_datetime(self):
5555
actual = dmp(self.arr_dt, self.arr3)
56-
ind = [0, 1, 5]
57-
expected = (self.arr_dt2.take(ind),
58-
self.arr3.take(ind).compressed())
56+
ind = [0, 1, 5]
57+
expected = (self.arr_dt2[ind], self.arr3[ind].compressed())
5958
assert_array_equal(actual[0], expected[0])
6059
assert_array_equal(actual[1], expected[1])
6160

6261
def test_rgba(self):
6362
actual = dmp(self.arr3, self.arr_rgba)
6463
ind = [0, 1, 5]
65-
expected = (self.arr3.take(ind).compressed(),
66-
self.arr_rgba.take(ind, axis=0))
64+
expected = (self.arr3[ind].compressed(), self.arr_rgba[ind])
6765
assert_array_equal(actual[0], expected[0])
6866
assert_array_equal(actual[1], expected[1])
6967

0 commit comments

Comments
 (0)