summaryrefslogtreecommitdiff
path: root/numpy/matlib.py
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-07-07 18:50:08 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-07-07 18:50:08 +0000
commit5ee14815b3520074e73b2b2836a8a11de0cc9fc2 (patch)
tree086de6656a9d438f1f652a44279295d78b671435 /numpy/matlib.py
parent876176a0412c4fb22645edc531110d2a0a2fed16 (diff)
downloadnumpy-5ee14815b3520074e73b2b2836a8a11de0cc9fc2.tar.gz
Add library of matrix functions.
Diffstat (limited to 'numpy/matlib.py')
-rw-r--r--numpy/matlib.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/numpy/matlib.py b/numpy/matlib.py
new file mode 100644
index 000000000..1707d7633
--- /dev/null
+++ b/numpy/matlib.py
@@ -0,0 +1,41 @@
+__all__ = ['ones','zeros','empty','identity','rand','randn','eye']
+
+from numpy.core.defmatrix import matrix, asmatrix
+from numpy import ndarray, array
+import numpy as N
+
+def empty(shape, dtype=None, order='C'):
+ """return an empty matrix of the given shape
+ """
+ return ndarray.__new__(matrix, shape, dtype, order=order)
+
+def ones(shape, dtype=None, order='C'):
+ """return a matrix initialized to all ones
+ """
+ a = ndarray.__new__(matrix, shape, dtype, order=order)
+ a.fill(1)
+ return a
+
+def zeros(shape, dtype=None, order='C'):
+ """return a matrix initialized to all zeros
+ """
+ a = ndarray.__new__(matrix, shape, dtype, order=order)
+ a.fill(0)
+ return a
+
+def identity(n,dtype=None):
+ """identity(n) returns the identity matrix of shape n x n.
+ """
+ a = array([1]+n*[0],dtype=dtype)
+ b = empty((n,n),dtype=dtype)
+ b.flat = a
+ return b
+
+def eye(N,M=None, k=0, dtype=float):
+ return asmatrix(N.eye(N,M,k,dtype))
+
+def rand(*args):
+ return asmatrix(N.rand(*args))
+
+def randn(*args):
+ return asmatrix(N.rand(*args))