python - Flipping along two axis in a multidimensional numpy array -


so i'm trying perform numerical calculations , in it, have flip first , second dimensions of multidimensional array. tried 2 methods , noticed first 1 gives wrong output , second method gives correct output. here code both:

for in range(i):     j in range(j):         w[:,:,i,j] = np.fliplr(w[:,:,i,j])         w[:,:,i,j] = np.flipud(w[:,:,i,j]) 

versus:

w = w[::-1,::-1,:,:] 

i decided try small test case see going on , looks both methods giving same answer:

a = np.array([[[1,2,3],[1,2,3]],[[1,2,3],[1,2,3]]]) print a[:,::-1,::-1] print a.shape  (i,j,k) = a.shape in range(i):     a[i,:,:] = np.fliplr(a[i,:,:])     a[i,:,:] = np.flipud(a[i,:,:]) print print a.shape 

could issue somewhere in code or there fundamentally different between 2 missing?

look @ code flip functions. apply ::-1 indexing different dimensions

def fliplr     m = asanyarray(m)     if m.ndim < 2:         raise valueerror("input must >= 2-d.")     return m[:, ::-1]     # ud: m[::-1, ...] 

so can do, can directly ::-1 indexing.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -