本文实例讲述了Python计算三维矢量幅度的方法。分享给大家供大家参考。具体如下:
1
2
3
4
5
6
7
8
9
10
|
from numpy import *
from math import *
a = ([ 'x' , 'y' , 'z' ])
sum_com = 0
for i in range ( 3 ):
y = input ( "Enter %s component:" % a[i])
m = y * * 2
sum_com + = m
magnitude = sqrt(sum_com)
print "The magnitude of vector is %s" % magnitude
|
希望本文所述对大家的Python程序设计有所帮助。