C-Types Foreign Function Interface (

Optionally SciPy-accelerated routines (

Mathematical functions with automatic domain (

numpy.lib.stride_tricks.sliding_window_view

Ifais 2-D, returns the diagonal ofawith the given offset, i.e., the collection of elements of the forma[i,i+offset]. Ifahas more than two dimensions, then the axes specified byaxis1andaxis2are used to determine the 2-D sub-array whose diagonal is returned. The shape of the resulting array can be determined by removingaxis1andaxis2and appending an index to the right equal to the size of the resulting diagonals.

In versions of NumPy prior to 1.7, this function always returned a new, independent array containing a copy of the values in the diagonal.

In NumPy 1.7 and 1.8, it continues to return a copy of the diagonal, but depending on this fact is deprecated. Writing to the resulting array continues to work as it used to, but a FutureWarning is issued.

Starting in NumPy 1.9 it returns a read-only view on the original array. Attempting to write to the resulting array will produce an error.

In some future release, it will return a read/write view and writing to the returned array will alter your original array. The returned array will have the same type as the input array.

If you dont write to the array returned by this function, then you can just ignore all of the above.

If you depend on the current behavior, then we suggest copying the returned array explicitly, i.e., useinstead of justnp.diagonal(a). This will work with both past and future versions of NumPy.

Array from which the diagonals are taken.

Offset of the diagonal from the main diagonal. Can be positive or negative. Defaults to main diagonal (0).

Axis to be used as the first axis of the 2-D sub-arrays from which the diagonals should be taken. Defaults to first axis (0).

Axis to be used as the second axis of the 2-D sub-arrays from which the diagonals should be taken. Defaults to second axis (1).

Ifais 2-D, then a 1-D array containing the diagonal and of the same type asais returned unlessais amatrix, in which case a 1-D array rather than a (2-D)matrixis returned in order to maintain backward compatibility.

Ifa.ndim2, then the dimensions specified byaxis1andaxis2are removed, and a new axis inserted at the end corresponding to the diagonal.

MATLAB work-a-like for 1-D and 2-D arrays.

Main diagonals of two arrays created by skipping

across the outer(left)-most axis last and

the middle (row) axis first.

The sub-arrays whose main diagonals we just obtained; note that each corresponds to fixing the right-most (column) axis, and that the diagonals are packed in rows.

The anti-diagonal can be obtained by reversing the order of elements using eithernumpy.flipudornumpy.fliplr.

Note that the order in which the diagonal is retrieved varies depending on the flip function.