To improve the speed I would like to avoid forloops.
I have a image array looking like :
image = np.zeros_like(np.zeros(shape=(480,640,1)),dtype=np.uint8)
and a typed np array Events with the following types
dtype = [('x', '<f8'),('y', '<f8'),('grayVal','<u2')
where 'x' = row and 'y' = column of the image array.
The Question is:
How can I assign the grayVal in Events to all the x and y in the image ?
So far I tried (and more not displayable): The For Loop:
for event in Events:
image[event['y'],event['x']] = event['grayVal']
and Indexing
events['y'].shape
(98210,)
events['x'].shape
(98210,)
events['grayVal'].shape
(98210,)
image[np.ix_(events['y'],events['x'])] = events['grayVal']
which somehow does not work due to the error message:
ValueError: shape mismatch: value array of shape (98210,) could not be broadcast to indexing result of shape (98210,98210,1)
What am I missing? Thanks for the help.
np.zeros(shape=(480,640), dtype=np.uint8)would describe an array that can be understood as a byte deep bitmap. I don't quite get where you would get the events from. Is it sparse, i.e. zero for most x,y pairs? Can you construct a minimal example (say for a 4 x4 matrix)? Leave out thets,p,cfor now unless you need them for the question.Events? And compared indexing with[x,y]versus[ix_(x,y)]?