diff options
author | Johannes Schönberger <jschoenberger@demuc.de> | 2013-05-06 21:06:35 +0200 |
---|---|---|
committer | Johannes Schönberger <jschoenberger@demuc.de> | 2013-06-06 21:15:45 +0200 |
commit | 91b1b99fa01d6c9991cc833f36beef87d3c0c595 (patch) | |
tree | 22ac614f4c6ce8a5290c5acb484138f93e7700ce /numpy/core/numeric.py | |
parent | 494fa219b050cb3b1564e78499c8306ea514aa35 (diff) | |
download | numpy-91b1b99fa01d6c9991cc833f36beef87d3c0c595.tar.gz |
Add examples to doc string of filled and filled_like
Diffstat (limited to 'numpy/core/numeric.py')
-rw-r--r-- | numpy/core/numeric.py | 25 |
1 files changed, 25 insertions, 0 deletions
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') |