summaryrefslogtreecommitdiff
path: root/numpy/lib/function_base.py
diff options
context:
space:
mode:
authorJoseph Paul Cohen <joseph@josephpcohen.com>2017-06-02 13:20:36 -0400
committerCharles Harris <charlesr.harris@gmail.com>2017-06-02 11:20:36 -0600
commitecab1ff2b77b06e0fcbbfafd26d80aef486f74b8 (patch)
tree15433f58645dfcc7e4ec6dbd4188981c35ef3734 /numpy/lib/function_base.py
parent090d46e76fbda7f7fc73751c221d0c58b9d889af (diff)
downloadnumpy-ecab1ff2b77b06e0fcbbfafd26d80aef486f74b8.tar.gz
MAINT: Use np.concatenate instead of np.vstack (#8934)
The np.vstack function is maintained for backward compatibility, it's use in new code is discouraged. * MAINT: Replace internal uses of vstack vstack is supported only for backward compatibility We should use concatenate or stack instead * MAINT: Remove 1d special casing in piecewise * STY: Fix missing blank line in ma.tests.test_extras.py
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r--numpy/lib/function_base.py16
1 files changed, 4 insertions, 12 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 8ee6a54dd..1418baa77 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -1321,16 +1321,8 @@ def piecewise(x, condlist, funclist, *args, **kw):
x = x[None]
zerod = True
if n == n2 - 1: # compute the "otherwise" condition.
- totlist = np.logical_or.reduce(condlist, axis=0)
- # Only able to stack vertically if the array is 1d or less
- if x.ndim <= 1:
- condlist = np.vstack([condlist, ~totlist])
- else:
- condlist = [asarray(c, dtype=bool) for c in condlist]
- totlist = condlist[0]
- for k in range(1, n):
- totlist |= condlist[k]
- condlist.append(~totlist)
+ condelse = ~np.any(condlist, axis=0, keepdims=True)
+ condlist = np.concatenate([condlist, condelse], axis=0)
n += 1
y = zeros(x.shape, x.dtype)
@@ -2982,7 +2974,7 @@ def cov(m, y=None, rowvar=True, bias=False, ddof=None, fweights=None,
>>> x = [-2.1, -1, 4.3]
>>> y = [3, 1.1, 0.12]
- >>> X = np.vstack((x,y))
+ >>> X = np.stack((x, y), axis=0)
>>> print(np.cov(X))
[[ 11.71 -4.286 ]
[ -4.286 2.14413333]]
@@ -3020,7 +3012,7 @@ def cov(m, y=None, rowvar=True, bias=False, ddof=None, fweights=None,
y = array(y, copy=False, ndmin=2, dtype=dtype)
if not rowvar and y.shape[0] != 1:
y = y.T
- X = np.vstack((X, y))
+ X = np.concatenate((X, y), axis=0)
if ddof is None:
if bias == 0: