Cleaned utils code, merged in subArray.

This commit is contained in:
Rowan Cockett
2013-07-30 22:56:36 -07:00
parent 68e44cca5a
commit 7e169bbb79
2 changed files with 12 additions and 15 deletions
-8
View File
@@ -1,8 +0,0 @@
import numpy as np
def getSubArray(A,ind):
"""subArray"""
i = ind[0]; j = ind[1]; k = ind[2]
return A[i,:,:][:,j,:][:,:,k]
+12 -7
View File
@@ -1,5 +1,5 @@
import numpy as np
from numpy import *
def reshapeF(x, size):
return np.reshape(x, size, order='F')
@@ -106,13 +106,13 @@ def ind2sub(shape, ind):
mult = [1]
for i in range(0, len(revshp)-1):
mult.extend([mult[i]*revshp[i]])
mult = array(mult).reshape(len(mult))
mult = np.array(mult).reshape(len(mult))
sub = []
for i in range(0, len(shape)):
sub.extend([math.floor(ind / mult[i])])
ind = ind - (math.floor(ind/mult[i]) * mult[i])
sub.extend([np.math.floor(ind / mult[i])])
ind = ind - (np.math.floor(ind/mult[i]) * mult[i])
return sub
@@ -122,7 +122,12 @@ def sub2ind(shape, subs):
mult = [1]
for i in range(0, len(revshp)-1):
mult.extend([mult[i]*revshp[i]])
mult = array(mult).reshape(len(mult), 1)
mult = np.array(mult).reshape(len(mult), 1)
idx = dot((subs), (mult))
return idx
idx = np.dot((subs), (mult))
return idx
def getSubArray(A, ind):
"""subArray"""
return A[ind[0], :, :][:, ind[1], :][:, :, ind[2]]