I have some data in one array that I want to map into another array, given an array of correspondences:
originaldatais a numpy 2D array,targetdatais another numpy 2D array,mappingis an array that maps between positions, somapping[x,y]gives me a pair of coordinates of where the data oftargetdata[x,y]comes from inoriginaldata.
So far I do something like this:
for (x,y) in ALLTHEPOINTS:
targetdata[x,y]=originaldata[mapping[x,y][0],mapping[x,y][1]]
...which I suspect is very inefficient.
Is there any way to vectorize this? Or is there any numpy function that addresses this type of operation?
targetdata[x,y]=originaldata[mapping[x, y, 0],mapping[x, y, 0]]?mappinga 3d array, ie (X, Y, 2), or is it an array of tuples or something similar?vectorizefunction, but it's not magic-speed-dust, just a wrapper for somefors. Regardless, it's a good baseline; use it and worry only if profiling says to.