Добрый день! Столкнулся с необходимостью реализации сортировки элементов матрицы (в частности, главной и побочной диагоналей). Т.к. Python недавно изучаю, голова от чтения документации пока что идет кругом.
Поэтому прошу помощи у Вас.
Буду благодарен за любую помощь, или наводку на примеры.

Есть реализация алгоритма на pascal:

var
  incr: array [0..23] of integer := (1, 4, 10, 23, 57, 145, 356, 911, 1968, 4711,
  11969, 27901, 84801, 213331, 543749, 1355339, 3501671, 8810089, 21521774,
  8548857, 157840433, 410151271, 1131376761, 2147483647);
  ch,ch2,n,q,k:integer;
  arr:array [0..1000] of integer;
  isx_ar:array [0..100,0..10] of integer;
    C: Boolean;
     G: Integer;
     I: Integer;
     J: Integer;
     Tmp: Integer;
     len: Integer;
     cur_inc: integer;
 begin
Write ('Введите размер исх. массива кол-во строк'); Readln (k);
Write ('Введите размер исх. массива кол-во столбцов'); Readln (q);
n:=0;
for ch2:=0 to k-1 do
begin
for ch:=0 to q-1 do
 begin
 isx_ar[ch2,ch]:=random(100)-random(100);
 arr[n]:=isx_ar[ch2,ch];
  write (isx_ar[ch2,ch],' ');
  inc(n);
 end;
writeln;
end;
n:=n-1;
//for i:=0 to n do Write (arr[i],' ');
 
  len := n;
  cur_inc := 0;
  while 3 * incr[cur_inc + 1] <= n do inc(cur_inc);
  repeat
    g := incr[cur_inc];
    i := g;
    repeat
      j := i - g;
      c := True;
      repeat
        if arr[j] >= arr[j + g] then
          c := False
        else
        begin
          Tmp := Arr[j];
          Arr[j] := Arr[j+g];
          Arr[j+g] := Tmp;
        end;
        dec(j, g);
      until  not ((j >= 0) and C);
      inc(i);
    until  not (i <= len);
    dec(cur_inc);
  until  not (cur_inc <> -1);
  n:=0;
  for ch2:=0 to k-1 do
begin
for ch:=0 to q-1 do
 begin
 isx_ar[ch2,ch]:=arr[n];
  write (isx_ar[ch2,ch],' ');
  inc(n);
 end;
writeln;
end;
end.