Python计算三维矢量幅度的方法

yipeiwu_com6年前Python基础

本文实例讲述了Python计算三维矢量幅度的方法。分享给大家供大家参考。具体如下:

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程序设计有所帮助。

相关文章

利用Python如何生成hash值示例详解

一、介绍 如果在Python中需要对用户输入的密码或者其他内容进行加密,首选的方法是生成hash值。 在Python中可以利用二个模块来进行:    &n...

利用Python复制文件的9种方法总结

利用Python复制文件的9种方法总结

以下是演示**“如何在Python中复制文件”的九种方法**。 shutil copyfile()方法 shutil copy()方法 shutil copyfileobj...

详解Python异常处理中的Finally else的功能

Python使用Try Exception来处理异常机制 若Exception中有Try对应的异常处理,则Try - exception之后的代码将被执行,但若Try - excepti...

python 获取et和excel的版本号

复制代码 代码如下:#-*- coding:utf-8 -*- from win32com.client import Dispatch if __name__ == '__main__...

python 读取文件并替换字段的实例

python 读取文件并替换字段的实例

如下所示: fp = open(''test2.txt','w') #打开你要写得文件test2.txt lines = open('test1.txt').readlines()...