python - in numpy what is the multi dimensional equivalent of take -


i have bit of code

def build_tree_base(blocks, x, y, z):    indicies = [         (x  ,z  ,y  ),         (x  ,z+1,y  ),         (x  ,z  ,y+1),         (x  ,z+1,y+1),         (x+1,z  ,y  ),         (x+1,z+1,y  ),         (x+1,z  ,y+1),         (x+1,z+1,y+1),     ]     children = [blocks[i] in indicies]     return node(children=children) 

where blocks 3 dimensional numpy array.

what i'd replace list comprehension numpy.take, take seems deal single dimension indices. there take work multidimensional indices?

also know transpose, slice , reshape, slow i'm looking better option.

how taking 2x2x2 slice, flat ?

import numpy np blocks = np.arange(2*3*4.).reshape((2,3,4)) i,j,k = 0,1,2 print [x x in blocks[i:i+2, j:j+2, k:k+2].flat] 

(flat iterator; expand this, or np.fromiter(), or let node iter on it.)


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -