diff options
Diffstat (limited to 'numpy/lib/shape_base.py')
-rw-r--r-- | numpy/lib/shape_base.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/numpy/lib/shape_base.py b/numpy/lib/shape_base.py index 280765df8..26c2aab04 100644 --- a/numpy/lib/shape_base.py +++ b/numpy/lib/shape_base.py @@ -857,16 +857,16 @@ def tile(A, reps): # numpy array and the repetitions are 1 in all dimensions return _nx.array(A, copy=True, subok=True, ndmin=d) else: + # Note that no copy of zero-sized arrays is made. However since they + # have no data there is no risk of an inadvertent overwrite. c = _nx.array(A, copy=False, subok=True, ndmin=d) - shape = list(c.shape) - n = max(c.size, 1) if (d < c.ndim): tup = (1,)*(c.ndim-d) + tup - for i, nrep in enumerate(tup): - if nrep != 1: - c = c.reshape(-1, n).repeat(nrep, 0) - dim_in = shape[i] - dim_out = dim_in*nrep - shape[i] = dim_out - n //= max(dim_in, 1) - return c.reshape(shape) + shape_out = tuple(s*t for s, t in zip(c.shape, tup)) + n = c.size + if n > 0: + for dim_in, nrep in zip(c.shape, tup): + if nrep != 1: + c = c.reshape(-1, n).repeat(nrep, 0) + n //= dim_in + return c.reshape(shape_out) |