summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorMarten van Kerkwijk <mhvk@astro.utoronto.ca>2017-05-12 10:13:39 -0400
committerMarten van Kerkwijk <mhvk@astro.utoronto.ca>2017-05-17 21:13:06 -0400
commitca49f0b11bc88056bf4767ac439b298cfda16fed (patch)
treef6109a40f862a9cb604d9328af9c74db6dec41d7 /numpy
parent18bac353f667da6969716b60f3d3315ffd0b7aaa (diff)
downloadnumpy-ca49f0b11bc88056bf4767ac439b298cfda16fed.tar.gz
DOC: update documentation allowing tuple of one in reduce, etc.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/add_newdocs.py39
-rw-r--r--numpy/core/code_generators/ufunc_docstrings.py8
-rw-r--r--numpy/core/tests/test_umath.py3
-rw-r--r--numpy/doc/subclassing.py2
4 files changed, 37 insertions, 15 deletions
diff --git a/numpy/add_newdocs.py b/numpy/add_newdocs.py
index 449196efb..7cf61c4d0 100644
--- a/numpy/add_newdocs.py
+++ b/numpy/add_newdocs.py
@@ -5444,9 +5444,11 @@ add_newdoc('numpy.core', 'ufunc',
----------
*x : array_like
Input arrays.
- out : ndarray or tuple of ndarray, optional
+ out : ndarray, None, or tuple of ndarray and None, optional
Alternate array object(s) in which to put the result; if provided, it
- must have a shape that the inputs broadcast to.
+ must have a shape that the inputs broadcast to. A tuple of arrays
+ (possible only as a keyword argument) must have length equal to the
+ number of outputs; use `None` for outputs to be allocated by the ufunc.
where : array_like, optional
Values of True indicate to calculate the ufunc at that position, values
of False indicate to leave the value in the output alone.
@@ -5667,9 +5669,14 @@ add_newdoc('numpy.core', 'ufunc', ('reduce',
The type used to represent the intermediate results. Defaults
to the data-type of the output array if this is provided, or
the data-type of the input array if no output array is provided.
- out : ndarray, optional
- A location into which the result is stored. If not provided, a
- freshly-allocated array is returned.
+ out : ndarray, None, or tuple of ndarray and None, optional
+ A location into which the result is stored. If not provided or `None`,
+ a freshly-allocated array is returned. For consistency with
+ :ref:`ufunc.__call__`, if given as a keyword, this may be wrapped in a
+ 1-element tuple.
+
+ .. versionchanged:: 1.13.0
+ Tuples are allowed for keyword argument.
keepdims : bool, optional
If this is set to True, the axes which are reduced are left
in the result as dimensions with size one. With this option,
@@ -5741,9 +5748,14 @@ add_newdoc('numpy.core', 'ufunc', ('accumulate',
The data-type used to represent the intermediate results. Defaults
to the data-type of the output array if such is provided, or the
the data-type of the input array if no output array is provided.
- out : ndarray, optional
- A location into which the result is stored. If not provided a
- freshly-allocated array is returned.
+ out : ndarray, None, or tuple of ndarray and None, optional
+ A location into which the result is stored. If not provided or `None`,
+ a freshly-allocated array is returned. For consistency with
+ :ref:`ufunc.__call__`, if given as a keyword, this may be wrapped in a
+ 1-element tuple.
+
+ .. versionchanged:: 1.13.0
+ Tuples are allowed for keyword argument.
keepdims : bool
Has no effect. Deprecated, and will be removed in future.
@@ -5820,9 +5832,14 @@ add_newdoc('numpy.core', 'ufunc', ('reduceat',
The type used to represent the intermediate results. Defaults
to the data type of the output array if this is provided, or
the data type of the input array if no output array is provided.
- out : ndarray, optional
- A location into which the result is stored. If not provided a
- freshly-allocated array is returned.
+ out : ndarray, None, or tuple of ndarray and None, optional
+ A location into which the result is stored. If not provided or `None`,
+ a freshly-allocated array is returned. For consistency with
+ :ref:`ufunc.__call__`, if given as a keyword, this may be wrapped in a
+ 1-element tuple.
+
+ .. versionchanged:: 1.13.0
+ Tuples are allowed for keyword argument.
Returns
-------
diff --git a/numpy/core/code_generators/ufunc_docstrings.py b/numpy/core/code_generators/ufunc_docstrings.py
index 7beda59f2..c5172f6a8 100644
--- a/numpy/core/code_generators/ufunc_docstrings.py
+++ b/numpy/core/code_generators/ufunc_docstrings.py
@@ -19,9 +19,11 @@ def get(name):
# common parameter text to all ufuncs
_params_text = textwrap.dedent("""
- out : ndarray or tuple of ndarray, optional
- Alternate array object(s) in which to put the result; if provided, it
- must have a shape that the inputs broadcast to.
+ out : ndarray, None, or tuple of ndarray and None, optional
+ A location into which the result is stored. If provided, it must have
+ a shape that the inputs broadcast to. If not provided or `None`,
+ a freshly-allocated array is returned. A tuple (possible only as a
+ keyword argument) must have length equal to the number of outputs.
where : array_like, optional
Values of True indicate to calculate the ufunc at that position, values
of False indicate to leave the value in the output alone.
diff --git a/numpy/core/tests/test_umath.py b/numpy/core/tests/test_umath.py
index 120844c82..97c9c25d5 100644
--- a/numpy/core/tests/test_umath.py
+++ b/numpy/core/tests/test_umath.py
@@ -2010,7 +2010,8 @@ class TestSpecialMethods(TestCase):
assert_raises(ValueError, inner1d, a, a, out=())
def test_ufunc_override_with_super(self):
-
+ # NOTE: this class is given as an example in doc/subclassing.py;
+ # if you make any changes here, do update it there too.
class A(np.ndarray):
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
args = []
diff --git a/numpy/doc/subclassing.py b/numpy/doc/subclassing.py
index 36d8ff97d..51d9dc120 100644
--- a/numpy/doc/subclassing.py
+++ b/numpy/doc/subclassing.py
@@ -489,6 +489,8 @@ following.
return NotImplemented
if method == 'at':
+ if isinstance(inputs[0], A):
+ inputs[0].info = info
return
if ufunc.nout == 1: