summaryrefslogtreecommitdiff
path: root/numpy/core/numeric.py
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-03-15 00:48:04 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-03-15 00:48:04 +0000
commit03736884e2fb993e096ef801dd49135b9292b823 (patch)
tree5556dc46592b881b33ae600e385c8578e3e4ebb6 /numpy/core/numeric.py
parent440214d5835da50d9dad3103835fb8b3967eb3b5 (diff)
downloadnumpy-03736884e2fb993e096ef801dd49135b9292b823.tar.gz
Changed the C-API by making the a.flags object a builtin object for speed. Also fixed issues with linalg and matrices.
Diffstat (limited to 'numpy/core/numeric.py')
-rw-r--r--numpy/core/numeric.py64
1 files changed, 42 insertions, 22 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py
index 0bb825cd8..d275367db 100644
--- a/numpy/core/numeric.py
+++ b/numpy/core/numeric.py
@@ -4,7 +4,7 @@ __all__ = ['newaxis', 'ndarray', 'flatiter', 'ufunc',
'getbuffer',
'where', 'concatenate', 'fastCopyAndTranspose', 'lexsort',
'register_dtype', 'set_numeric_ops', 'can_cast',
- 'asarray', 'asanyarray', 'isfortran', 'zeros_like', 'empty_like',
+ 'asarray', 'asanyarray', 'isfortran', 'empty_like', 'zeros_like',
'correlate', 'convolve', 'inner', 'dot', 'outer', 'vdot',
'alterdot', 'restoredot', 'cross',
'array2string', 'get_printoptions', 'set_printoptions',
@@ -25,6 +25,47 @@ from umath import *
import numerictypes
from numerictypes import *
+# from Fernando Perez's IPython
+def zeros_like(a):
+ """Return an array of zeros of the shape and typecode of a.
+
+ If you don't explicitly need the array to be zeroed, you should instead
+ use empty_like(), which is faster as it only allocates memory."""
+ try:
+ return zeros(a.shape, a.dtype, a.flags.fnc)
+ except AttributeError:
+ try:
+ wrap = a.__array_wrap__
+ except AttributeError:
+ wrap = None
+ a = asarray(a)
+ res = zeros(a.shape, a.dtype)
+ if wrap:
+ res = wrap(res)
+ return res
+
+def empty_like(a):
+ """Return an empty (uninitialized) array of the shape and typecode of a.
+
+ Note that this does NOT initialize the returned array. If you require
+ your array to be initialized, you should use zeros_like().
+
+ """
+ try:
+ return empty(a.shape, a.dtype, a.flags.fnc)
+ except AttributeError:
+ try:
+ wrap = a.__array_wrap__
+ except AttributeError:
+ wrap = None
+ a = asarray(a)
+ res = empty(a.shape, a.dtype)
+ if wrap:
+ res = wrap(res)
+ return res
+
+# end Fernando's utilities
+
def extend_all(module):
adict = {}
for a in __all__:
@@ -81,27 +122,6 @@ def asanyarray(a, dtype=None, copy=False, fortran=False, ndmin=0):
def isfortran(a):
return a.flags['FNC']
-# from Fernando Perez's IPython
-def zeros_like(a):
- """Return an array of zeros of the shape and typecode of a.
-
- If you don't explicitly need the array to be zeroed, you should instead
- use empty_like(), which is faster as it only allocates memory."""
- a = asanyarray(a)
- return a.__array_wrap__(zeros(a.shape, a.dtype, a.flags['FNC']))
-
-def empty_like(a):
- """Return an empty (uninitialized) array of the shape and typecode of a.
-
- Note that this does NOT initialize the returned array. If you require
- your array to be initialized, you should use zeros_like().
-
- """
- a = asanyarray(a)
- return a.__array_wrap__(empty(a.shape, a.dtype, a.flags['FNC']))
-
-# end Fernando's utilities
-
_mode_from_name_dict = {'v': 0,
's' : 1,
'f' : 2}