简单矩阵类 [英] Simple Matrix class

查看:79
本文介绍了简单矩阵类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的网站上发布了一个简单的Matrix类,作为一个小型的

软件包,用于对基本计算大约10x10的矩阵进行基本计算(

大小)没有理论上的限制,但反向的表现是指数的。)

包括:

- 追踪

- 转置

- 共轭

- 行列式

- 反向

- 特征向量/值(对称矩阵)

- 加法和乘法(用常数或其他矩阵)


矩阵很容易用格式化的字符串构建,如:


m = Matrix("" 1 2 3 4

5 11 20 3

2 7 11 1

0 5 3 1""") />

几乎没有附加条件的许可证,只是不要麻烦我

保修,支持,适销性,准确性等一些小事。 br />

http://www.geocities.com/ptmcg/pytho...html#matrix_py

- Paul

I''ve posted a simple Matrix class on my website as a small-footprint
package for doing basic calculations on matrices up to about 10x10 in
size (no theoretical limit, but performance on inverse is exponential).
Includes:
- trace
- transpose
- conjugate
- determinant
- inverse
- eigenvectors/values (for symmetric matrices)
- addition and multiplication (with constant or other matrix)

Matrices are easily built from formatted strings, as in:

m = Matrix( """1 2 3 4
5 11 20 3
2 7 11 1
0 5 3 1""")

Pretty much a no-strings-attached license, just don''t hassle me about
little things like warranty, support, merchantability, accuracy, etc.
See it at
http://www.geocities.com/ptmcg/pytho...html#matrix_py

-- Paul

推荐答案

当你不需要时,你是否可以平移矩阵求逆?


" Paul麦奎尔" < pt *** @ austin.rr.comwrote:
Do you calcalate the matrix inversion, when you don''t need to?

"Paul McGuire" <pt***@austin.rr.comwrote:

>我已经在我的网站上发布了一个简单的Matrix类,占用空间很小/>用于对大小约10x10的矩阵进行基本计算的包(没有理论限制,但反向性能是指数级的)。

包括:
- trace
- 转置
- 共轭
- 行列式
- 逆
- 特征向量/值(对称矩阵)
- 加法和乘法(用常数或其他矩阵)

矩阵很容易用格式化的字符串构建,例如:

m =矩阵("1 2 3 4

5 11 20 3

2 7 11 1

0 5 3 1""")

几乎没有附带字符串的许可证,请不要麻烦我关于保修,支持,适销性,准确性等的小事。

http://www.geocities.com/ptmcg/pytho...html#matrix_py

- - 保罗
>I''ve posted a simple Matrix class on my website as a small-footprint
package for doing basic calculations on matrices up to about 10x10 in
size (no theoretical limit, but performance on inverse is exponential).
Includes:
- trace
- transpose
- conjugate
- determinant
- inverse
- eigenvectors/values (for symmetric matrices)
- addition and multiplication (with constant or other matrix)

Matrices are easily built from formatted strings, as in:

m = Matrix( """1 2 3 4
5 11 20 3
2 7 11 1
0 5 3 1""")

Pretty much a no-strings-attached license, just don''t hassle me about
little things like warranty, support, merchantability, accuracy, etc.
See it at
http://www.geocities.com/ptmcg/pytho...html#matrix_py

-- Paul



-

问候,

凯西

--
Regards,
Casey

1月23日下午4:05,Casey Hawthorne< caseyhHAMMER_T ... @ istar.ca>

写道:
On Jan 23, 4:05 pm, Casey Hawthorne <caseyhHAMMER_T...@istar.ca>
wrote:

当你不需要时,你是否可以平移矩阵求逆?
Do you calcalate the matrix inversion, when you don''t need to?



不,反演只在第一次调用inverse()时计算,

并记忆,以便后续调用立即返回缓存值

。由于Matrix类是可变的,因此如果更新了任何矩阵元素,则缓存无效。所以在

改变一个矩阵元素后,反转将在

下次调用inverse()时重新计算。


希望这清除了事情。您也可以进行自己的实验,

包括向memoizing装饰器添加详细日志记录 - 源代码中包含一个

示例。另外,脚印非常小,只有一个Python源文件,大约600-700行代码,所有Python都是
,所以100%便携。


- Paul

No, the inversion is only calculated on the first call to inverse(),
and memoized so that subsequent calls return the cached value
immediately. Since the Matrix class is mutable, the cache is
invalidated if any of the matrix elements are updated. So after
changing a matrix element, the inversion would be recalculated at the
next call to inverse().

Hope that clears things up. You can also do your own experiments,
including adding verbose logging to the memoizing decorators - an
example is included in the source code. Also the footprint is quite
small, just one Python source file, about 600-700 lines of code, and
all Python, so 100% portable.

-- Paul


Paul McGuire写道:
Paul McGuire wrote:

我在我的网站上发布了一个简单的Matrix类,作为一个小型的

软件包,用于对基本计算大约10x10的基本计算

大小(没有理论限制) ,但反向的表现是指数的)。
I''ve posted a simple Matrix class on my website as a small-footprint
package for doing basic calculations on matrices up to about 10x10 in
size (no theoretical limit, but performance on inverse is exponential).



为什么?一个简单而强大的LU分解应该不超过O(n ** 3)。


-

Robert Kern

我已经开始相信整个世界都是一个谜,一个无害的谜团

由于我们疯狂地试图解释它而使它变得可怕,好像它已经
一个潜在的事实。

- Umberto Eco

Why is that? A simple and robust LU decomposition should be no more than O(n**3).

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco


这篇关于简单矩阵类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆