Is there any way to avoid using a second for loop for an operation like this?
for x in range(Size_1):
for y in range(Size_2):
k[x,y] = np.sqrt(x+y) - y
Or is there a better way to optimize this? Right now it is incredibly slow for large sizes.
Here's a vectorized solution with broadcasting -
X,Y = np.ogrid[:Size_1,:Size_2]
k_out = np.sqrt(X+Y) - Y
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With