summaryrefslogtreecommitdiff
path: root/numpy/core/numeric.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core/numeric.py')
-rw-r--r--numpy/core/numeric.py12
1 files changed, 3 insertions, 9 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py
index 31b021b71..c961bcc0f 100644
--- a/numpy/core/numeric.py
+++ b/numpy/core/numeric.py
@@ -1692,15 +1692,9 @@ def identity(n, dtype=None):
[ 0., 0., 1.]])
"""
- a = array([1]+n*[0],dtype=dtype)
- b = empty((n,n),dtype=dtype)
-
- # Note that this assignment depends on the convention that since the a
- # array is shorter than the flattened b array, then the a array will
- # be repeated until it is the appropriate size. Given a's construction,
- # this nicely sets the diagonal to all ones.
- b.flat = a
- return b
+ a = zeros((n,n), dtype=dtype)
+ a.flat[::n+1] = 1
+ return a
def allclose(a, b, rtol=1.e-5, atol=1.e-8):
"""