diff options
Diffstat (limited to 'numpy/oldnumeric/olddefaults.py')
-rw-r--r-- | numpy/oldnumeric/olddefaults.py | 39 |
1 files changed, 13 insertions, 26 deletions
diff --git a/numpy/oldnumeric/olddefaults.py b/numpy/oldnumeric/olddefaults.py index 356f5f00c..384261437 100644 --- a/numpy/oldnumeric/olddefaults.py +++ b/numpy/oldnumeric/olddefaults.py @@ -1,45 +1,32 @@ -__all__ = ['ones', 'empty', 'identity', 'zeros', 'eye', 'tri'] +__all__ = ['ones', 'empty', 'identity', 'zeros'] import numpy.core.multiarray as mu import numpy.core.numeric as nn - -def ones(shape, dtype=int, order='C'): +from typeconv import convtypecode + +def ones(shape, typecode='l', savespace=0, dtype=None): """ones(shape, dtype=int) returns an array of the given dimensions which is initialized to all ones. """ - a = mu.empty(shape, dtype, order) + dtype = convtypecode(typecode,dtype) + a = mu.empty(shape, dtype) a.fill(1) return a -def zeros(shape, dtype=int, order='C'): +def zeros(shape, typecode='l', savespace=0, dtype=None): """zeros(shape, dtype=int) returns an array of the given dimensions which is initialized to all zeros """ - return mu.zeros(shape, dtype, order) + dtype = convtypecode(typecode,dtype) + return mu.zeros(shape, dtype) -def identity(n,dtype=int): +def identity(n,typecode='l', dtype=None): """identity(n) returns the identity 2-d array of shape n x n. """ + dtype = convtypecode(typecode, dtype) 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 = nn.equal(nn.subtract.outer(nn.arange(N), nn.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 = nn.greater_equal(nn.subtract.outer(nn.arange(N), nn.arange(M)),-k) - if m.dtype != dtype: - return m.astype(dtype) - -def empty(shape, dtype=int, order='C'): +def empty(shape, typecode='l', dtype=None): + dtype = convtypecode(typecode, dtype) return mu.empty(shape, dtype, order) |