diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-08-16 15:08:53 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-08-16 15:08:53 -0700 |
commit | d4af6123a609b062af7ed23e106b6bfffd482e7f (patch) | |
tree | ecfbced2ba34d1e2e74029cd40044c16b92455d3 /numpy/add_newdocs.py | |
parent | ec418015d1a8e947feb3ca2868d976ee252782ec (diff) | |
parent | acef718f40a30188c1379c13cc49c920d9e7c303 (diff) | |
download | numpy-d4af6123a609b062af7ed23e106b6bfffd482e7f.tar.gz |
Merge pull request #2821 from ContinuumIO/ufunc-fancy-indexing3
in place fancy indexing for ufuncs
Diffstat (limited to 'numpy/add_newdocs.py')
-rw-r--r-- | numpy/add_newdocs.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/numpy/add_newdocs.py b/numpy/add_newdocs.py index 5bb800488..65a416a9f 100644 --- a/numpy/add_newdocs.py +++ b/numpy/add_newdocs.py @@ -5815,6 +5815,59 @@ add_newdoc('numpy.core', 'ufunc', ('outer', """)) +add_newdoc('numpy.core', 'ufunc', ('at', + """ + at(a, indices, b=None) + + 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 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: + + >>> a = np.array([1, 2, 3, 4]) + >>> np.negative.at(a, [0, 1]) + >>> print(a) + array([-1, -2, 3, 4]) + + :: + + Increment items 0 and 1, and increment item 2 twice: + + >>> a = np.array([1, 2, 3, 4]) + >>> np.add.at(a, [0, 1, 2, 2], 1) + >>> print(a) + array([2, 3, 5, 4]) + + :: + + Add items 0 and 1 in first array to second array, + and store results in first array: + + >>> 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]) + + """)) ############################################################################## # |