I have a function like this (which I cannot change):
def myFunc(x, y):
nx = int(x)
ny = int(y)
Freq = 0.4
e0 = 1 * gen.noise2d(Freq * nx, Freq * ny)
return e0 + 500
Right now, I am trying to use an np.ndarray
for other parts of my code, and pass in the x
and y
values in my loop one at a time:
# passing in a particles which is an array like this:
# [[2,4], [5, 9], [2, 5]]
# this array would have more than 5000 pairs of x, y coordinates
def mapFunc(particles):
N = len(particles)
mask = []
distance = []
for i in range(N):
x = particles[i][0]
y = particles[i][1]
ground_dist = mapFunc(x, y)
# add in the distances to the ground
distance.append(ground_dist)
# add True if the ground is less than 50 feet away
mask.append(ground_dist < 50)
return distance, mask
Is there a better/faster/more efficient way to get the values from my np.ndarray
? Can I somehow pass in the whole arrary into myFunc
? The problem is int(x)
and int(y)
, not sure how to work with that in Python in regards to an array.
Edit 1 - There was a mistake in the return of myFunc, it was supposed to be using e0 to add 500
Edit 2 - the gen.noise2d is from https://github.com/lmas/opensimplex to "Generate 2D OpenSimplex noise from X,Y coordinates."