[Numpy-discussion] speed up np.diag

Pauli Virtanen pav@iki...
Fri Jul 10 10:11:27 CDT 2009


Fri, 10 Jul 2009 15:55:58 +0100, Citi, Luca kirjoitti:
[clip]
> ## SUGGESTED
> def diag(v, k=0):
>     v = asarray(v)
>     s = v.shape
>     if len(s) == 1:
[clip]
>     elif len(s) == 2:
>         if v.flags.f_contiguous:
>             v, k, s = v.T, -k, s[::-1]

Is this correct? The .flat iterator always traverses the array in virtual 
C-order, not in the order it's laid out in memory.

-- 
Pauli Virtanen



More information about the NumPy-Discussion mailing list