From 04c341da469150701fe7def6c98955485425b388 Mon Sep 17 00:00:00 2001 From: Jay Bourque Date: Wed, 14 Nov 2012 12:08:17 -0600 Subject: Update documentation for 'at' method --- numpy/add_newdocs.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'numpy/add_newdocs.py') diff --git a/numpy/add_newdocs.py b/numpy/add_newdocs.py index 5bb800488..adfbc5b5a 100644 --- a/numpy/add_newdocs.py +++ b/numpy/add_newdocs.py @@ -5815,6 +5815,47 @@ add_newdoc('numpy.core', 'ufunc', ('outer', """)) +add_newdoc('numpy.core', 'ufunc', ('at', + """ + at(a, indices, b=None) + + Performs operation in place on array for items specified by indices. + Items can be listed more than once and operation will be performed + on result of operation on previous item. + + Equivalent to a[indices] += b for addition ufunc, except that results + are accumulated for indices listed more than once. + + Parameters + ---------- + a : array_like + The array to act on. + indices : array_like + Paired indices, comma separated (not colon), specifying slices to + reduce. + b : array_like or scalar + Second operation for ufuncs requiring two operands. + + Examples + -------- + Set items 0 and 1 to their negative values: + + np.negative.at(a, [0, 1]) + + :: + + Increment items 0 and 1, and increment item 2 twice: + + np.add.at(a, [0, 1, 2, 2], 1) + + :: + + Add items 0 and 1 in first array to second array, + and store results in first array: + + np.add.at(a, [0, 1], b) + + """)) ############################################################################## # -- cgit v1.2.1 From 13c1847ba2f0eab36004491deb0e2b8e1140c133 Mon Sep 17 00:00:00 2001 From: Jay Bourque Date: Wed, 19 Dec 2012 14:12:21 -0600 Subject: Reword some comments/documentation --- numpy/add_newdocs.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'numpy/add_newdocs.py') diff --git a/numpy/add_newdocs.py b/numpy/add_newdocs.py index adfbc5b5a..e630ae921 100644 --- a/numpy/add_newdocs.py +++ b/numpy/add_newdocs.py @@ -5820,11 +5820,14 @@ add_newdoc('numpy.core', 'ufunc', ('at', at(a, indices, b=None) Performs operation in place on array for items specified by indices. - Items can be listed more than once and operation will be performed - on result of operation on previous item. - - Equivalent to a[indices] += b for addition ufunc, except that results - are accumulated for indices listed more than once. + For addition ufunc, this method is equivalent to a[indices] += b, + except that results are accumulated for indices listed more than once. + This solves the problem with a[indices] += b where each time a duplicate + index is encounted, the increment is performed on the original element. + As a result, an element that appears three times in the fancy indexing + list will only be incremented once in the final result, whereas with the + new 'at' method the original element will be incremented by three in the + final result. Parameters ---------- -- cgit v1.2.1 From 79bc97caa1bd23919ba8cb63850e12cbf5097b97 Mon Sep 17 00:00:00 2001 From: Jay Bourque Date: Sat, 27 Jul 2013 12:45:37 -0500 Subject: Update docs --- numpy/add_newdocs.py | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'numpy/add_newdocs.py') diff --git a/numpy/add_newdocs.py b/numpy/add_newdocs.py index e630ae921..ba5e11f21 100644 --- a/numpy/add_newdocs.py +++ b/numpy/add_newdocs.py @@ -5819,44 +5819,50 @@ add_newdoc('numpy.core', 'ufunc', ('at', """ at(a, indices, b=None) - Performs operation in place on array for items specified by indices. - For addition ufunc, this method is equivalent to a[indices] += b, - except that results are accumulated for indices listed more than once. - This solves the problem with a[indices] += b where each time a duplicate - index is encounted, the increment is performed on the original element. - As a result, an element that appears three times in the fancy indexing - list will only be incremented once in the final result, whereas with the - new 'at' method the original element will be incremented by three in the - final result. + Performs unbuffered in place operation on operand 'a' for elements + specified by 'indices'. For addition ufunc, this method is equivalent to + `a[indices] += b`, except that results are accumulated for elements that + are indexed more than once. For example, `a[[0,0]] += 1` will only + increment the first element once because of buffering, whereas + `add.at(a, [0,0], 1)` will increment the first element twice. Parameters ---------- a : array_like - The array to act on. - indices : array_like - Paired indices, comma separated (not colon), specifying slices to - reduce. - b : array_like or scalar - Second operation for ufuncs requiring two operands. + The array to perform in place operation on. + indices : array_like or tuple + Array like index object or slice object for indexing into first + operand. If first operand has multiple dimensions, indices can be a + tuple of array like index objects or slice objects. + b : array_like + Second operand for ufuncs requiring two operands. Operand must be + broadcastable over first operand after indexing or slicing. Examples -------- Set items 0 and 1 to their negative values: - np.negative.at(a, [0, 1]) + >>> a = np.array([1, 2, 3, 4]) + >>> np.negative.at(a, [0, 1]) + array([-1, -2, 3, 4]) :: Increment items 0 and 1, and increment item 2 twice: - np.add.at(a, [0, 1, 2, 2], 1) + >>> a = np.array([1, 2, 3, 4]) + >>> np.add.at(a, [0, 1, 2, 2], 1) + array([2, 3, 5, 4]) :: Add items 0 and 1 in first array to second array, and store results in first array: - np.add.at(a, [0, 1], b) + >>> a = np.array([1, 2, 3, 4]) + >>> b = np.array([1, 2]) + >>> np.add.at(a, [0, 1], b) + array([2, 4, 3, 4]) """)) -- cgit v1.2.1 From 7c4eeea6a60672a52ff6cf0bf75ee9beaf5c391c Mon Sep 17 00:00:00 2001 From: Jay Bourque Date: Mon, 5 Aug 2013 11:34:43 -0500 Subject: Update docs --- numpy/add_newdocs.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'numpy/add_newdocs.py') diff --git a/numpy/add_newdocs.py b/numpy/add_newdocs.py index ba5e11f21..c26ea36c2 100644 --- a/numpy/add_newdocs.py +++ b/numpy/add_newdocs.py @@ -5844,6 +5844,7 @@ add_newdoc('numpy.core', 'ufunc', ('at', >>> a = np.array([1, 2, 3, 4]) >>> np.negative.at(a, [0, 1]) + >>> print a array([-1, -2, 3, 4]) :: @@ -5852,6 +5853,7 @@ add_newdoc('numpy.core', 'ufunc', ('at', >>> a = np.array([1, 2, 3, 4]) >>> np.add.at(a, [0, 1, 2, 2], 1) + >>> print a array([2, 3, 5, 4]) :: @@ -5862,6 +5864,7 @@ add_newdoc('numpy.core', 'ufunc', ('at', >>> a = np.array([1, 2, 3, 4]) >>> b = np.array([1, 2]) >>> np.add.at(a, [0, 1], b) + >>> print a array([2, 4, 3, 4]) """)) -- cgit v1.2.1 From a04bb37b9346ec8c2867ba09f8a76b6615d10200 Mon Sep 17 00:00:00 2001 From: Jay Bourque Date: Mon, 5 Aug 2013 13:49:06 -0500 Subject: Update docs --- numpy/add_newdocs.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'numpy/add_newdocs.py') diff --git a/numpy/add_newdocs.py b/numpy/add_newdocs.py index c26ea36c2..65a416a9f 100644 --- a/numpy/add_newdocs.py +++ b/numpy/add_newdocs.py @@ -5844,7 +5844,7 @@ add_newdoc('numpy.core', 'ufunc', ('at', >>> a = np.array([1, 2, 3, 4]) >>> np.negative.at(a, [0, 1]) - >>> print a + >>> print(a) array([-1, -2, 3, 4]) :: @@ -5853,7 +5853,7 @@ add_newdoc('numpy.core', 'ufunc', ('at', >>> a = np.array([1, 2, 3, 4]) >>> np.add.at(a, [0, 1, 2, 2], 1) - >>> print a + >>> print(a) array([2, 3, 5, 4]) :: @@ -5864,7 +5864,7 @@ add_newdoc('numpy.core', 'ufunc', ('at', >>> a = np.array([1, 2, 3, 4]) >>> b = np.array([1, 2]) >>> np.add.at(a, [0, 1], b) - >>> print a + >>> print(a) array([2, 4, 3, 4]) """)) -- cgit v1.2.1