summaryrefslogtreecommitdiff
path: root/numpy/matrixlib/defmatrix.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/matrixlib/defmatrix.py')
-rw-r--r--numpy/matrixlib/defmatrix.py50
1 files changed, 25 insertions, 25 deletions
diff --git a/numpy/matrixlib/defmatrix.py b/numpy/matrixlib/defmatrix.py
index 1ca835af2..0a73725c2 100644
--- a/numpy/matrixlib/defmatrix.py
+++ b/numpy/matrixlib/defmatrix.py
@@ -39,7 +39,7 @@ else:
del k
def _eval(astr):
- str_ = astr.translate(_table,_todelete)
+ str_ = astr.translate(_table, _todelete)
if not str_:
raise TypeError("Invalid data string supplied: " + astr)
else:
@@ -95,7 +95,7 @@ def asmatrix(data, dtype=None):
"""
return matrix(data, dtype=dtype, copy=False)
-def matrix_power(M,n):
+def matrix_power(M, n):
"""
Raise a square matrix to the (integer) power `n`.
@@ -169,7 +169,7 @@ def matrix_power(M,n):
M = asanyarray(M)
if len(M.shape) != 2 or M.shape[0] != M.shape[1]:
raise ValueError("input must be a square array")
- if not issubdtype(type(n),int):
+ if not issubdtype(type(n), int):
raise TypeError("exponent must be an integer")
from numpy.linalg import inv
@@ -185,21 +185,21 @@ def matrix_power(M,n):
result = M
if n <= 3:
for _ in range(n-1):
- result=N.dot(result,M)
+ result=N.dot(result, M)
return result
# binary decomposition to reduce the number of Matrix
# multiplications for n > 3.
beta = binary_repr(n)
- Z,q,t = M,0,len(beta)
+ Z, q, t = M, 0, len(beta)
while beta[t-q-1] == '0':
- Z = N.dot(Z,Z)
+ Z = N.dot(Z, Z)
q += 1
result = Z
- for k in range(q+1,t):
- Z = N.dot(Z,Z)
+ for k in range(q+1, t):
+ Z = N.dot(Z, Z)
if beta[t-k-1] == '1':
- result = N.dot(result,Z)
+ result = N.dot(result, Z)
return result
@@ -271,9 +271,9 @@ class matrix(N.ndarray):
if (ndim > 2):
raise ValueError("matrix must be 2-dimensional")
elif ndim == 0:
- shape = (1,1)
+ shape = (1, 1)
elif ndim == 1:
- shape = (1,shape[0])
+ shape = (1, shape[0])
order = False
if (ndim == 2) and arr.flags.fortran:
@@ -304,9 +304,9 @@ class matrix(N.ndarray):
else:
newshape = self.shape
if ndim == 0:
- self.shape = (1,1)
+ self.shape = (1, 1)
elif ndim == 1:
- self.shape = (1,newshape[0])
+ self.shape = (1, newshape[0])
return
def __getitem__(self, index):
@@ -330,13 +330,13 @@ class matrix(N.ndarray):
except:
n = 0
if n > 1 and isscalar(index[1]):
- out.shape = (sh,1)
+ out.shape = (sh, 1)
else:
- out.shape = (1,sh)
+ out.shape = (1, sh)
return out
def __mul__(self, other):
- if isinstance(other,(N.ndarray, list, tuple)) :
+ if isinstance(other, (N.ndarray, list, tuple)) :
# This promotes 1-D vectors to row vectors
return N.dot(self, asmatrix(other))
if isscalar(other) or not hasattr(other, '__rmul__') :
@@ -378,7 +378,7 @@ class matrix(N.ndarray):
orientation.
"""
if axis is None:
- return self[0,0]
+ return self[0, 0]
elif axis==0:
return self
elif axis==1:
@@ -391,7 +391,7 @@ class matrix(N.ndarray):
to a scalar like _align, but are using keepdims=True
"""
if axis is None:
- return self[0,0]
+ return self[0, 0]
else:
return self
@@ -862,7 +862,7 @@ class matrix(N.ndarray):
[ 0., 1.]])
"""
- M,N = self.shape
+ M, N = self.shape
if M == N:
from numpy.dual import inv as func
else:
@@ -997,7 +997,7 @@ class matrix(N.ndarray):
H = property(getH, None, doc="hermitian (conjugate) transpose")
I = property(getI, None, doc="inverse")
-def _from_string(str,gdict,ldict):
+def _from_string(str, gdict, ldict):
rows = str.split(';')
rowtup = []
for row in rows:
@@ -1018,8 +1018,8 @@ def _from_string(str,gdict,ldict):
raise KeyError("%s not found" % (col,))
coltup.append(thismat)
- rowtup.append(concatenate(coltup,axis=-1))
- return concatenate(rowtup,axis=0)
+ rowtup.append(concatenate(coltup, axis=-1))
+ return concatenate(rowtup, axis=0)
def bmat(obj, ldict=None, gdict=None):
@@ -1084,10 +1084,10 @@ def bmat(obj, ldict=None, gdict=None):
arr_rows = []
for row in obj:
if isinstance(row, N.ndarray): # not 2-d
- return matrix(concatenate(obj,axis=-1))
+ return matrix(concatenate(obj, axis=-1))
else:
- arr_rows.append(concatenate(row,axis=-1))
- return matrix(concatenate(arr_rows,axis=0))
+ arr_rows.append(concatenate(row, axis=-1))
+ return matrix(concatenate(arr_rows, axis=0))
if isinstance(obj, N.ndarray):
return matrix(obj)