I am trying to populate a 2D numpy array. In my experience, the following is not going to scale up well with array sizes.
x=np.array([2,3,4])
y=np.array([1,3,9,13])
mat=np.zeros((x.size,y.size))
for i in range(nx):
for j in range(ny):
if x[i] > y[j]:
mat[i,j] = 1
else:
mat[i,j] = -1
Ideally, I would like to use list comprehension like It would be simple if it was 1D only
mat=np.asarray([foo(x_) for x_ in x])
but how to generalize this to 2D np.arrays?
Other numpy based solutions are also suitable, but efficiency is the key metric here