From 91b1b99fa01d6c9991cc833f36beef87d3c0c595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Mon, 6 May 2013 21:06:35 +0200 Subject: Add examples to doc string of filled and filled_like --- numpy/core/numeric.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'numpy/core/numeric.py') diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index d0ae5e6eb..d3199cdea 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -269,6 +269,15 @@ def filled(shape, val, dtype=None, order='C'): ones : Return a new array setting values to one. empty : Return a new uninitialized array. + Examples + -------- + >>> np.filled((2, 2), np.inf) + array([[ inf, inf], + [ inf, inf]]) + >>> np.filled((2, 2), 10, dtype=np.int) + array([[10, 10], + [10, 10]]) + """ a = empty(shape, dtype, order) multiarray.copyto(a, val, casting='unsafe') @@ -312,6 +321,22 @@ def filled_like(a, val, dtype=None, order='K', subok=True): empty : Return a new uninitialized array. filled : Fill a new array. + Examples + -------- + >>> x = np.arange(6, dtype=np.int) + >>> np.filled_like(x, 1) + array([1, 1, 1, 1, 1, 1]) + >>> np.filled_like(x, 0.1) + array([0, 0, 0, 0, 0, 0]) + >>> np.filled_like(x, 0.1, dtype=np.double) + array([ 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]) + >>> np.filled_like(x, np.nan, dtype=np.double) + array([ nan, nan, nan, nan, nan, nan]) + + >>> y = np.arange(6, dtype=np.double) + >>> np.filled_like(y, 0.1) + array([ 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]) + """ res = empty_like(a, dtype=dtype, order=order, subok=subok) multiarray.copyto(res, val, casting='unsafe') -- cgit v1.2.1