diff options
author | Travis Oliphant <oliphant@enthought.com> | 2006-06-30 20:04:28 +0000 |
---|---|---|
committer | Travis Oliphant <oliphant@enthought.com> | 2006-06-30 20:04:28 +0000 |
commit | 7d4c3ed2a0caebf1ce9e0da3473fdbde005699e5 (patch) | |
tree | fa4801786b5c59f13deff0bdf1cf25c3c8656224 /numpy/oldnumeric/olddefaults.py | |
parent | ec1662fb0182a87ebf39ec476109becfc7a8cdb1 (diff) | |
download | numpy-7d4c3ed2a0caebf1ce9e0da3473fdbde005699e5.tar.gz |
Make the default array type float.
Diffstat (limited to 'numpy/oldnumeric/olddefaults.py')
-rw-r--r-- | numpy/oldnumeric/olddefaults.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/numpy/oldnumeric/olddefaults.py b/numpy/oldnumeric/olddefaults.py new file mode 100644 index 000000000..d818ed57c --- /dev/null +++ b/numpy/oldnumeric/olddefaults.py @@ -0,0 +1,45 @@ +__all__ = ['ones', 'empty', 'identity', 'zeros', 'eye', 'tri'] + +import numpy.core.multiarray as mu +import numpy.core.numeric as nn + +def ones(shape, dtype=int, order='C'): + """ones(shape, dtype=int) returns an array of the given + dimensions which is initialized to all ones. + """ + a = mu.empty(shape, dtype, order) + a.fill(1) + return a + +def zeros(shape, dtype=int, order='C'): + """zeros(shape, dtype=int) returns an array of the given + dimensions which is initialized to all zeros + """ + return mu.zeros(shape, dtype, order) + +def identity(n,dtype=int): + """identity(n) returns the identity 2-d array of shape n x n. + """ + return nn.identity(n, dtype) + +def eye(N, M=None, k=0, dtype=int): + """ eye returns a N-by-M 2-d array where the k-th diagonal is all ones, + and everything else is zeros. + """ + if M is None: M = N + m = equal(subtract.outer(arange(N), arange(M)),-k) + if m.dtype != dtype: + return m.astype(dtype) + +def tri(N, M=None, k=0, dtype=int): + """ returns a N-by-M array where all the diagonals starting from + lower left corner up to the k-th are all ones. + """ + if M is None: M = N + m = greater_equal(subtract.outer(arange(N), arange(M)),-k) + if m.dtype != dtype: + return m.astype(dtype) + +def empty(shape, dtype=int, order='C'): + return mu.empty(shape, dtype, order) + |