目前我的代码采用向量并构成第三个:
for b in range(2047):
for a in range(b+1,2048):
vector1 = (l[b][0],l[b][1],l[b][2])
vector2 = (l[a][0],l[a][1],l[a][2])
x = vector1
y = vector2
vector3 = list(np.array(x) - np.array(y))
dotProduct = reduce( operator.add, map( operator.mul, vector3, vector3))
dp = dotProduct**.5
data_points = dp
bin = int(dp/bin_width)
if bin < num_bins:
bins[bin][2] += 1.0/bin_volumes[bin]
ps b = 36771.881 但我想说,如果(矢量3点积与b)大于(b点积b)/ 2 然后向量3 =向量3 - b
且if(Vector 3 dot product b)小于(-b dot product with b)/ 2
然后矢量3 =矢量3 + b
如何将它添加到我的循环中,以便每次创建向量3时它会检查这两种情况的向量3?
正在使用的包:
import operator
import matplotlib.pyplot as plt
import numpy as np
当前代码:
limit = 36771.881
for b in range(2047):
for a in range(b+1,2048):
vector1 = (l[b][0],l[b][1],l[b][2])
vector2 = (l[a][0],l[a][1],l[a][2])
x = vector1
y = vector2
vector3 = list(np.array(x) - np.array(y))
dotProduct = reduce( operator.add, map( operator.mul, vector3, vector3))
dp = dotProduct**.5
data_points = dp
if np.dot(data_points,limit) > (np.dot(limit,limit)
dp = dp - limit
bin = int(dp/bin_width)
if bin < num_bins:
# add 1 to the count of that bin
bins[bin][2] += 1.0/bin_volumes[bin]
else np.dot(data_points,limit) < (np.dot(-limit,limit)
dp = dp + limit
bin = int(dp/bin_width)
if bin < num_bins:
# add 1 to the count of that bin
bins[bin][2] += 1.0/bin_volumes[bin]
else if
bin = int(dp/bin_width)
if bin < num_bins:
# add 1 to the count of that bin
bins[bin][2] += 1.0/bin_volumes[bin]
答案 0 :(得分:0)
对于两个数组a
和b
,numpy.dot
返回内积(“点积”)。
如,
>>> import numpy as np
>>> x = np.array([4,5,6])
>>> y = np.array([1,2,3])
>>> np.dot(x,y)
32
>>> np.dot(x,y) == (x * y).sum()
True