Name
diagonal
Synopsis
diagonal(a
,k
=0,axis1
=0,axis2
=1)
Returns the elements of a
whose index
along axis1
and index along
axis2
differ by
k
. When a
has
rank 2
, this means the main diagonal when
k
equals 0
,
subdiagonals above the main one when k
is
greater than 0
, and subdiagonals below the main
one when k
is less than
0
. For example:
# a is [[0 1 2 3] # [4 5 6 7] # [8 9 10 11] # [12 13 14 15]] print Numeric.diagonal(a) # prints: [0 5 10 15] print Numeric.diagonal(a,1) # prints: [1 6 11] print Numeric.diagonal(a,-1) # prints: [4 9 14]
As shown,
diagonal(
a
)
is the main diagonal,
diagonal(
a
,1)
the subdiagonal just above the main one, and
diagonal(
a
,-1)
the subdiagonal just below the main one.
Get Python in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.