let transpose a =
if not (is_rectangular a) then invalid_arg "Math.transpose: not-rectangular";
let n_rows = Array.length a in
if Array.length a = 0 || Array.length a.(0) = 0 then [| |]
else
let n_cols = Array.length a.(0) in
let ans = Array.make_matrix n_cols n_rows a.(0).(0) in
for i = 0 to n_rows - 1 do
for j = 0 to Array.length a.(i) - 1 do
ans.(j).(i) <- a.(i).(j)
done
done;
ans