python - Numpy: array of indices based on array shape? -
say have simple array:
a = np.zeros([3,3]) >>> [ 0 0 0 , 0 0 0 , 0 0 0 ]
is there utility function give me array same dimensions contains "coordinates" of each point on a
? so,
ia = np.indexer(a) >>> [ (0,0) (0,1) (0,2), (1,0) (1,1) (1,2), (2,0) (2,1) (2,2) ]
? want vectorize operation using np.ndenumerate, easier if output of ndenumerate in matrix form.
class glwidget(qtopengl.qglwidget): target_array = none ... def paintgl(self): glclear(gl_color_buffer_bit | gl_depth_buffer_bit) self.render() def render(self): if self.target_array none: return starting_abs_point = -(np.array(self.target_array.shape)-1)/(2*np.max(self.target_array.shape)) gltranslate(*starting_abs_point) last_rel_coords= np.zeros(3) idx, value in np.ndenumerate(self.target_array): # vectorization target! rel_coords = np.array(idx)/np.max(self.target_array.shape) step = rel_coords-last_rel_coords last_rel_coords = rel_coords gltranslate(*step) glutwirecube(value/( np.max(self.target_array)*np.max(self.target_array.shape) )) gltranslate(*-(starting_abs_point+last_rel_coords))
goal (it looks terrible because can't lighting , stuff going yet, it's learning exercise):
Comments
Post a Comment