Created
May 7, 2012 12:06
-
-
Save odebeir/2627432 to your computer and use it in GitHub Desktop.
BSP - Monday 7 May
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
n = 4 | |
data = np.reshape(range(4*4),(n,n)) | |
data = data[:,:,np.newaxis] | |
print data[:,:,0],data.shape | |
seq = [0,1,2,3] | |
"""seq | |
0 : up/down | |
1 : down/up | |
2 : left/right | |
3 : right/left | |
""" | |
def fold(data,seq): | |
if len(seq) == 0: | |
print 'last=',data[0,0,:] | |
return data | |
if seq[0]==0: | |
n2 = data.shape[0]/2 | |
dfold = np.dstack((data[n2-1::-1,:],data[n2:,:])) | |
fold(dfold,seq[1:]) | |
if seq[0]==1: | |
n2 = data.shape[0]/2 | |
dfold = np.dstack((data[:n2-1:-1,:],data[:n2,:])) | |
fold(dfold,seq[1:]) | |
if seq[0]==2: | |
n2 = data.shape[1]/2 | |
dfold = np.dstack((data[:,n2-1::-1],data[:,n2:])) | |
fold(dfold,seq[1:]) | |
if seq[0]==3: | |
n2 = data.shape[1]/2 | |
dfold = np.dstack((data[:,:n2-1:-1],data[:,:n2])) | |
fold(dfold,seq[1:]) | |
fold(data,seq) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment