diff options
author | Mark Wiebe <mwwiebe@gmail.com> | 2011-08-16 09:07:16 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2011-08-27 07:26:54 -0600 |
commit | 99a21efff4b1f2292dc370c7c9c7c58f10385f2a (patch) | |
tree | c1526f43815ade40b38e22e63ee01341b36dff84 /numpy/lib | |
parent | 91e94e925764177637bc17465404a75b16c35701 (diff) | |
download | numpy-99a21efff4b1f2292dc370c7c9c7c58f10385f2a.tar.gz |
ENH: missingdata: Add NA support to np.diagonal, change np.diagonal to always return a view
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/twodim_base.py | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/numpy/lib/twodim_base.py b/numpy/lib/twodim_base.py index d95a59e3f..9b3b50d04 100644 --- a/numpy/lib/twodim_base.py +++ b/numpy/lib/twodim_base.py @@ -221,10 +221,12 @@ def diag(v, k=0): """ Extract a diagonal or construct a diagonal array. + As of NumPy 1.7, extracting a diagonal always returns a view into `v`. + Parameters ---------- v : array_like - If `v` is a 2-D array, return a copy of its `k`-th diagonal. + If `v` is a 2-D array, return a view of its `k`-th diagonal. If `v` is a 1-D array, return a 2-D array with `v` on the `k`-th diagonal. k : int, optional @@ -278,16 +280,7 @@ def diag(v, k=0): res[:n-k].flat[i::n+1] = v return res elif len(s) == 2: - if k >= s[1]: - return empty(0, dtype=v.dtype) - if v.flags.f_contiguous: - # faster slicing - v, k, s = v.T, -k, s[::-1] - if k >= 0: - i = k - else: - i = (-k) * s[1] - return v[:s[1]-k].flat[i::s[1]+1] + return v.diagonal(k) else: raise ValueError("Input must be 1- or 2-d.") |