n维向量数学库。

ndvector的Python项目详细描述


关于

ndvector是python3的另一个向量数学库。努比关注的地方 在包括厨房水槽在内的所有设备上,ndvector旨在提供 简单的、pythonic的、面向对象的api,用于n维向量数学。

许可证

apache许可证2.0(请参阅许可证)

要求

python=3.5

用法

用法试图达到您的预期。只需导入库,创建 点和向量对象,并对它们进行数学运算。

fromn_dimensionimportVectorv1=Vector(1.0,0.0)v2=Vector(-1.0,1.0)v3=v1+v2print(v3)# => Vector ‹0.0, 1.0›

API

给定:

- s a scalar (float)

- p, p# are instances of Point

- v, v# are instances of Vector

Point

- constructor - create a Point from one or more float parameters, a tuple
	of floats, or a list of floats

- properties:

	- dimension - the dimension of the Point

- operators:

	- 'p + v' addition of a Vector to a Point to get the Point at the tip of
		the Vector if the tail of the vector is moved to the Point

	- 'p1 - p2' subtraction of a Point from a Point to get the Vector between
		the Points

	- 'p1 == p2' equality (See Note 1)

	- 'p1 != p2' not equality (See Note 1)

Vector

- constructor - create a Vector from one or more float parameters, a tuple
	of floats, or a list of floats

- properties:
	- dimension - the dimension of the vector
	- magnitude - the magnitude of the vector

- operators

	- 'v1 + v2' vector addition

	- 'v1 - v2' vector subtraction

	- 'v1 * v2' scalar aka dot product (v1 * v2 => scalar)

	- 'v * s' scale vector

	- 'v1 @ v2' vector aka cross product (v1 * v2 => vector) (See Note 2)

	- 'v1 == v2' equality (See Note 1)

	- 'v1 != v2' not equality (See Note 1)

- methods

	- angle() - find the angle in radians between the vector and another vector

	- normalize() - find a unit vector with the same direction as the vector

注释

  1. 当涉及到浮点数时,测试相等性是很棘手的。nU维度 如果两个浮点数的绝对值 差额小于一定数额;目前0.000001似乎 干得好。在进行更多测试后,可能会改进此功能
  2. 仅对三维(3)向量实现

测试

使用toxpytest进行测试。见 https://tox.readthedocs.io/en/latest/获取有关安装tox的信息。 通过克隆源存储库并将其更改为本地存储库来运行测试 工作目录,并调用tox

git clone https://github.com/tkegan/n_dimension.git
cd n_dimension
tox

待办事项

  • 创建更好的API文档

  • 通过将某些功能移到编译的代码中来研究加速的性能,但前提是纯python实现可以作为回退而保留

贡献

我欢迎针对github存储库的pull请求。如果扩展API,请包括测试。在测试到位并通过之前,我不会将更改合并到api。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何将HashMap<String,Object>从一个活动传递到另一个活动   java如何手动加密socket连接的流量?   java正则表达式生成一个不正确的结果   Java方法引用具有泛型参数的方法   java app setBackground()错误:不兼容的类型:int无法转换为Drawable   java是启动Spring引导而不是SpringApplication的其他方法。跑   无法打开java类路径资源[org/quartz/impl/jdbcjobstore/tables_h2.sql],因为它不存在   spring使用Java,如何确定来自tomcat Web服务器的出站服务调用?   java获取多个同名的XML元素JAXB   java使用Ant从同一代码库构建Swing和Android应用程序   JComponent的java重绘方法不起作用   java目标不可访问,标识符“beanName”解析为null   smtp是否有支持esmtp管道的java api?   java如何在Spring中自动连接业务对象   java在Hibernate中没有其他保存实体的方法吗?   针对两个客户机的SpringJavaWeb应用程序项目开发   使用split的java标记化输入