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

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

相关文章

PyQt6在全新电脑怎么样安装

在全新的电脑上安装 PyQt6,你需要先确保你的电脑上已安装了 Python 和 pip(Python 的包管理器)。以下是详细的步骤指导: 1. 安装 Python访问 Python 官方网站 下...

Anaconda下配置python+opencv+contribx的实例讲解

Anaconda下配置python+opencv+contribx的实例讲解

先吐槽一下opencv 3.1.0的版本cv2.sift和surf就不能用了 看解释是说 什么 "non-free",,必须要到opencv_contrib库中才有,而这个库的编译不是...

python更新列表的方法

本文实例讲述了python更新列表的方法。分享给大家供大家参考。具体如下: aList = [123, 'abc', 4.56, ['inner', 'list'], (7-9j)]...

python的turtle库使用详解

python的turtle库使用详解

python中的turtle库是3.6版本中新推出的绘图工具库,那么如何使用呢?下面小编给大家分享一下。 首先打开pycharm软件,右键单击选择新建一个python file 接下来...

Python模块搜索路径代码详解

简述 由于某些原因,在使用 import 时,Python 找不到相应的模块。这时,解释器就会发牢骚 - ImportError。 那么,Python 如何知道在哪里搜索模块的路径呢?...