[ Checking a variable ]
Currently I have code that takes to vectors and makes a third one:
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 But I want to say that if (vector 3 dot product with b) is greater than (b dot product b)/2 Then vector 3 = vector3 - b
and if (Vector 3 dot product b) is less than (-b dot product with b)/2
then vector 3 = vector 3 + b
How do I add this into my loop so that it checks vector 3 for these two situations every time it makes a vector 3?
packages being used :
import operator
import matplotlib.pyplot as plt
import numpy as np
current code:
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]
Answer 1
For two arrays a
and b
, numpy.dot
returns the inner product ("dot product").
E.g.,
>>> 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