我试图找到阵列的最小值并打印出来。容易吗?显然不是。我的代码:
array = generateAtoms(num)
arrayPoints, vArraySum = moveMolecule(array, numSteps=steps)
plotSetUp(arrayPoints)
#print vArraySum
print min(vArraySum), " kJ/mol is the minimum potential achieved"
我希望我的回答在-0.19范围内。如果我不打印上面的打印声明,我的输出大约是9,000,000 kJ / mol。如果我打印它,我的打印声明就像预期的那样。
以下是vArraySum
的示例(如果我运行打印):
[88824.74221919772, 18198.301666484836, 3531.2537391848105, 3531.2537391848105,
3531.2537391848105, 16.432760713742276, -0.09559319207145775, -0.09559319207145775,
-0.19379982167330503, -0.19379982167330503, -0.19379982167330503, -0.19379982167330503,
-0.19379982167330503, -0.19379982167330503, -0.19379982167330503, -0.19379982167330503,
-0.19379982167330503, -0.19379982167330503, -0.19379982167330503, -0.19379982167330503]
当我观察"我的输出如何变化?它(使用打印)?我完全失败了。要添加,每次900万个数字不是相同的数字,但每次约为900万。
EDIT2:
def moveMolecule(array, numSteps):
# Moves molecules in random directions by adding random array
# Will not move points if potential of system increases
points = []
vArray = []
vArraySum = []
progress = 0
points.append(array)
for i in range(numSteps):
addArray = np.random.uniform(low=-0.2, high=0.2, size=(num,3))
if sumV(np.add(array, addArray)) < sumV(array):
array = np.add(array, addArray)
else:
array = array
points.append(array)
vArray.append(vArrays(array))
vArraySum.append(sumV(array))
# Updates progress bar
progress = updateProgressBar(progress, i, numSteps)
plotV(points, vArray)
return points, vArraySum
EDIT3:
def functionV(r):
# Function to calculate LJ potential
return ((4 * _e) * (((_d / r) ** 12) - ((_d / r) ** 6)))
def sumV(array):
# Uses NN search to calculate sum of potential of system
V = []
# Performs NN search to collect nearby radii
points = NNSearchSetUp(array)
radius = NNSearch(points)
# Calculate potential for NNs
for r in radius:
V.append(functionV(r))
return sum(V)
答案 0 :(得分:0)
想出来。 vArraySum是一个numpy数组。一定不能玩min?谢谢@John。将数组转换为浮点数修复了问题