March 2003
Intermediate to advanced
656 pages
39h 30m
English
diagonal
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.
Read now
Unlock full access