After calculating the coordinates of the points on a three-dimensional grid, and storing the values obtained in the following arrays:
import numpy as np
x = np.zeros(4*4*8, float)
y = np.zeros(4*4*8, float)
z = np.zeros(4*4*8, float)
for l in range(4*4*8):
x[l], y[l], z[l] = np.unravel_index(l, (8, 4, 4))
I define my matrix as
def getMatrix(kappa, x, y, z):
nxnynz = 4*4*8
nrange_x = np.arange(nxnynz)
nrange_y = nrange_x
w, r = np.meshgrid(nrange_x, nrange_y)
delta_r = np.sqrt(((x[w]-x[r])**2)+((y[w]-y[r])**2)+((z[w]-z[r])**2)*)
matrix = np.zeros(delta_r.shape)
matrix[delta_r == 0] = 4.*kappa/(nxnynz**3.)
matrix[delta_r != 0] = np.sin(kappa*2.*np.pi*delta_r[delta_r != 0])/(delta_r[delta_r != 0]*float(nxnynz))
where the crucial point is the different definition for those values when delta_r == 0 and when delta_r != 0.
Now, in addition to this specification, I need to add a further one, namely the condition (in badly written code, just to give the idea)
if ((abs(w-r)) % 8 ) != 0:
matrix[w][r] = 0.
where w and r are the same indices used before. How can I fit this new condition in the previous definition of the matrix?
kappais a scalar? Also, how aboutmatrix[((abs(w-r)) % 8 ) != 0] = 0? Wouldn't that solve it?delta_r = np.sqrt(((x[w]-x[r])**2)+((y[w]-y[r])**2)+((z[w]-z[r])**2)*)incomplete?