这是我的代码:
import numpy as np
cx = np.array([0, 0, 3, 3])
cy = np.array([0, 3, 4, 0])
M = len(cx)
for j in range(M):
wx = 0
wy = 0
for i in range(M):
if i == j:
continue
x = cx[i] - cx[j]
y = cy[i] - cy[j]
wx += -x / np.sqrt(x ** 2 + y ** 2)
wy += -y / np.sqrt(x ** 2 + y ** 2)
Move = (
wx / np.sqrt(wx ** 2 + wy ** 2),
wy / np.sqrt(wx ** 2 + wy ** 2),
)
我的代码有什么问题? 非常感谢您的帮助
答案 0 :(得分:0)
# A tibble: 8 x 6
# Groups: Group, Damage [4]
Group Hormone Damage Score Greater new
<chr> <chr> <chr> <int> <int> <int>
1 B control damaged 4 1 1
2 B control undamaged 4 1 1
3 B JA damaged 2 0 0
4 B JA undamaged 3 0 0
5 D control damaged 2 0 0
6 D control undamaged 1 0 0
7 D JA damaged 4 1 1
8 D JA undamaged 3 1 1
答案 1 :(得分:0)
尝试一下:
import numpy as np
cx = np.array([0, 0, 3, 3])
cy = np.array([0, 3, 4, 0])
M = len(cx)
for j in range(M):
wx = 0
wy = 0
for i in range(M):
if i == j:
continue
x = cx[i] - cx[j]
y = cy[i] - cy[j]
wx += -x / np.sqrt(x ** 2 + y ** 2)
wy += -y / np.sqrt(x ** 2 + y ** 2)
Move = (
wx / np.sqrt(wx ** 2 + wy ** 2),
wy / np.sqrt(wx ** 2 + wy ** 2),
)
print(Move)