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将列表中的元素转化为数字并排序的示例

本文实例讲述了Python中列表元素转为数字的方法。分享给大家供大家参考,具体如下: 有一个数字字符的列表: numbers = ['2', '4', '1', '3'] 想要把每...

Python3.5 Pandas模块之DataFrame用法实例分析

Python3.5 Pandas模块之DataFrame用法实例分析

本文实例讲述了Python3.5 Pandas模块之DataFrame用法。分享给大家供大家参考,具体如下: 1、DataFrame的创建 (1)通过二维数组方式创建 #!/...

Django接收post前端返回的json格式数据代码实现

post接收字符串 def subscription(request): msg = request.POST.get('msg') # tel_no = request....

Python学习笔记之While循环用法分析

本文实例讲述了Python学习笔记之While循环用法。分享给大家供大家参考,具体如下: 前面一篇《Python学习笔记之For循环用法》详细介绍了Python for循环,这里再来讲述...

对Python实现累加函数的方法详解

这个需求比较奇怪,要求实现Sum和MagaSum函数,实现以下功能 Sum(1) =>1 Sum(1,2,3) =>6 MegaSum(1)() =>1 MegaS...