def view(A, offset=<NUM_LIT:0>):
from numpy.lib.stride_tricks import as_strided<EOL>assert A.ndim == <NUM_LIT:2>, "<STR_LIT>"<EOL>assert A.shape[<NUM_LIT:0>] == A.shape[<NUM_LIT:1>], "<STR_LIT>"<EOL>if offset > <NUM_LIT:0>:<EOL><INDENT>return as_strided(A[<NUM_LIT:0>, offset:], shape=(A.shape[<NUM_LIT:0>] - offset, ), strides=((A.shape[<NUM_LIT:0>]+<NUM_LIT:1>)*A.itemsize, ))<EOL><DEDENT>elif offset < <NUM_LIT:0>:<EOL><INDENT>return as_strided(A[-offset:, <NUM_LIT:0>], shape=(A.shape[<NUM_LIT:0>] + offset, ), strides=((A.shape[<NUM_LIT:0>]+<NUM_LIT:1>)*A.itemsize, ))<EOL><DEDENT>else:<EOL><INDENT>return as_strided(A, shape=(A.shape[<NUM_LIT:0>], ), strides=((A.shape[<NUM_LIT:0>]+<NUM_LIT:1>)*A.itemsize, ))<EOL><DEDENT>
Get a view on the diagonal elements of a 2D array.

This is actually a view (!) on the diagonal of the array, so you can
in-place adjust the view.

:param :class:`ndarray` A: 2 dimensional numpy array
:param int offset: view offset to give back (negative entries allowed)
:rtype: :class:`ndarray` view of diag(A)

>>> import numpy as np
>>> X = np.arange(9).reshape(3,3)
>>> view(X)
array([0, 4, 8])
>>> d = view(X)
>>> d += 2
>>> view(X)
array([ 2,  6, 10])
>>> view(X, offset=-1)
array([3, 7])
>>> subtract(X, 3, offset=-1)
array([[ 2,  1,  2],
       [ 0,  6,  5],
       [ 6,  4, 10]])