diff options
| author | Matti Picus <matti.picus@gmail.com> | 2019-04-15 10:46:34 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-04-15 10:46:34 +0300 |
| commit | 37da972f018a5605aba398b2dacc103f619971cf (patch) | |
| tree | 9b1137bdc268716abc8c336cde7869b394b3ca1b /numpy/core/fromnumeric.py | |
| parent | f5749f9df9aef4c0ec18a8968d8a02a0f18d6ea7 (diff) | |
| parent | e44713c51421bcf53e4babcc97574b9143bdd7a0 (diff) | |
| download | numpy-37da972f018a5605aba398b2dacc103f619971cf.tar.gz | |
Merge pull request #13316 from AnderUstarroz/added-antidiagonal-examples
DOC: Added anti-diagonal examples to np.diagonal and np.fill_diagonal
Diffstat (limited to 'numpy/core/fromnumeric.py')
| -rw-r--r-- | numpy/core/fromnumeric.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py index b4e5965d2..801ef972d 100644 --- a/numpy/core/fromnumeric.py +++ b/numpy/core/fromnumeric.py @@ -1532,9 +1532,9 @@ def diagonal(a, offset=0, axis1=0, axis2=1): [2, 3]], [[4, 5], [6, 7]]]) - >>> a.diagonal(0, # Main diagonals of two arrays created by skipping - ... 0, # across the outer(left)-most axis last and - ... 1) # the "middle" (row) axis first. + >>> a.diagonal(0, # Main diagonals of two arrays created by skipping + ... 0, # across the outer(left)-most axis last and + ... 1) # the "middle" (row) axis first. array([[0, 6], [1, 7]]) @@ -1542,13 +1542,28 @@ def diagonal(a, offset=0, axis1=0, axis2=1): corresponds to fixing the right-most (column) axis, and that the diagonals are "packed" in rows. - >>> a[:,:,0] # main diagonal is [0 6] + >>> a[:,:,0] # main diagonal is [0 6] array([[0, 2], [4, 6]]) - >>> a[:,:,1] # main diagonal is [1 7] + >>> a[:,:,1] # main diagonal is [1 7] array([[1, 3], [5, 7]]) + The anti-diagonal can be obtained by reversing the order of elements + using either `numpy.flipud` or `numpy.fliplr`. + + >>> a = np.arange(9).reshape(3, 3) + >>> a + array([[0, 1, 2], + [3, 4, 5], + [6, 7, 8]]) + >>> np.fliplr(a).diagonal() # Horizontal flip + array([2, 4, 6]) + >>> np.flipud(a).diagonal() # Vertical flip + array([6, 4, 2]) + + Note that the order in which the diagonal is retrieved varies depending + on the flip function. """ if isinstance(a, np.matrix): # Make diagonal of matrix 1-D to preserve backward compatibility. |
