There is a code:
import math import numpy as np X = [ 0.0, 0.0, 0.0, 0.0, 0.0] Y = [ 0.0, 0.25, 0.5, 0.75, 1.0] G = [ -0.5818708816896146, -0.17982884214560324, -1.3877787807814457e-17, 0.1798288421456033, 0.5818708816896146] X, Y, G = map(np.array, [X, Y,G ]) # Подсчет скоростей r22 = ((X[:] - X[:,None]) ** 2 + (Y[:] - Y[:,None]) ** 2) Vx = (Y[:] - Y[:,None]) * G[:] / (2 * math.pi * r22) Vy = (X[:] - X[:,None]) * G[:] / -(2 * math.pi * r22) As a result, we get:
#r22 [[ 0. 0.0625 0.25 0.5625 1. ] [ 0.0625 0. 0.0625 0.25 0.5625] [ 0.25 0.0625 0. 0.0625 0.25 ] [ 0.5625 0.25 0.0625 0. 0.0625] [ 1. 0.5625 0.25 0.0625 0. ]] #Vx [[ nan -0.11448 -0. 0.03816 0.09261] [ 0.37043 nan -0. 0.05724 0.12348] [ 0.18522 0.11448 nan 0.11448 0.18522] [ 0.12348 0.05724 0. nan 0.37043] [ 0.09261 0.03816 0. -0.11448 nan]] #Vy [[ nan 0. 0. -0. -0.] [ 0. nan 0. -0. -0.] [ 0. 0. nan -0. -0.] [ 0. 0. 0. nan -0.] [ 0. 0. 0. -0. nan]] A similar question was asked here , but that was the case for one sheet of X, but there are several sheets here , but I failed to set the condition correctly using the previous answer.
The essence of the question is: how to set the condition correctly in the list generator or in the numpy code so that there are no zeros in r22 and, accordingly, division by zero in subsequent Vx and Vy (if i is an element of sheet X and j is an element of sheet Y, then if i = j - do not subtract).
#Нужный результат r22 [[ 0.0625 0.25 0.5625 1. ] [ 0.0625 0.0625 0.25 0.5625] [ 0.25 0.0625 0.0625 0.25 ] [ 0.5625 0.25 0.0625 0.0625] [ 1. 0.5625 0.25 0.0625]] #Нужный результат Vx [[ -0.11448 -0. 0.03816 0.09261] [ 0.37043 -0. 0.05724 0.12348] [ 0.18522 0.11448 0.11448 0.18522] [ 0.12348 0.05724 0. 0.37043] [ 0.09261 0.03816 0. -0.11448]] #Нужный результат Vy [[ 0. 0. -0. -0.] [ 0. 0. -0. -0.] [ 0. 0. -0. -0.] [ 0. 0. 0. -0.] [ 0. 0. 0. -0.]]
X,Y,G? - MaxU