I am trying to iterate the source array in order to change a few elements in the destination array, but I can’t get the correct indexes, I have incomprehensible offsets. In general, my task is to change the element if the conditions require it
import numpy as np
x = np.linspace(0,1000, 1000/50)
y = np.linspace(0,1000, 1000/50)
X,Y = np.meshgrid(x,y)
source = np.column_stack([X.ravel(), Y.ravel()]).astype(int)
destination = source.copy()
for x, i in np.ndenumerate(source):
# if smth:
destination[i] = np.array([x[0] + 10, x[1]])
I think I should not use the source array, but only iterate over the destination array(сannot be done using standard methods), tell me the correct solution, thanks in advance.
Current output:
[421 789]
[473 789]
[526 789]
[578 789]
[631 789]
[684 789]
Required output:
[431 789]
[483 789]
[536 789]
[588 789]
[641 789]
[694 789]
I’ll explain more simply, I have a grid, it has points, I need to shift the points, say 88, 89, 90, 10 pixels to the right, for this I need to have an array of source and destination (where these points are offset), enumerate most likely it doesn’t suit me, but the usual editing of an array like for x in destination: when editing x gives the desired result, but this does not apply to ndarray
for x, i in enumerate(destination):
inside = cv2.pointPolygonTest(cnt, (destination[x,0],
destination[x,1]), False)
if inside > 0:
cv2.circle(img, (destination[x,0], destination[x,1]), 10,
(255,0,0), 2)
destination[x] = np.array([destination[x,0] + 10, destination[x,1]])
# Contour(cnt)
[[550 42]
[600 42]
[690 273]
[640 273]]
As you understand, I need to shift everything that is circled in blue by 10 pixels

if smth:sounds like a task fornp.wheredesiredvalues? what is the mathematical equation behind?