【发布时间】:2017-09-14 05:36:12
【问题描述】:
这个程序是为了找到一个向量的归一化,但我无法打印列表:
定义函数:
def _unit_vector_sample_(vector):
# calculate the magnitude
x = vector[0]
y = vector[1]
z = vector[2]
mag = ((x**2) + (y**2) + (z**2))**(1/2)
# normalize the vector by dividing each component with the magnitude
new_x = x/mag
new_y = y/mag
new_z = z/mag
unit_vector = [new_x, new_y, new_z]
#return unit_vector
主程序:
vector=[2,3,-4]
def _unit_vector_sample_(vector):
print(unit_vector)
如何纠正错误?
【问题讨论】:
-
将您的问题修复为实际问题并正确格式化您的代码以供显示。
标签: python-3.x list function