From 778af02eb7c1668e751f435cd2a4952a362a0433 Mon Sep 17 00:00:00 2001 From: Julian Taylor Date: Tue, 29 Jul 2014 20:04:28 +0200 Subject: BUG: fix string type inconsistency between zeros and zeros_like np.zeros for strings returns empty strings while np.zeros_like of a string array creates strings containing an string 0. --- numpy/core/numeric.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'numpy/core/numeric.py') diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index a85e8514c..57784a51f 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -131,7 +131,9 @@ def zeros_like(a, dtype=None, order='K', subok=True): """ res = empty_like(a, dtype=dtype, order=order, subok=subok) - multiarray.copyto(res, 0, casting='unsafe') + # needed instead of a 0 to get same result as zeros for for string dtypes + z = zeros(1, dtype=res.dtype) + multiarray.copyto(res, z, casting='unsafe') return res def ones(shape, dtype=None, order='C'): -- cgit v1.2.1