python是否能够执行MATLAB等效矩阵运算? [英] Is python capable of doing MATLAB equivalent matrix operations?

查看:355
本文介绍了python是否能够执行MATLAB等效矩阵运算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在MATLAB中实现了可在216x216矩阵上运行的代码,这些矩阵包含数字数据和某些时候的字符串.我在这些矩阵上执行的操作主要类似于高于某个阈值的过滤器矩阵,查找所有高于某个值的矩阵索引,查找高于X的值列表,然后查找它们之间的连续差值,以及一些字符串替换操作.做矩阵点积等.我需要访问数千个文件来生成这些矩阵(我在MATLAB中使用的dlmread).

I have implemented codes in MATLAB that operates on 216x216 matrices that contain numeric data and sometime strings. The operations that I do on these matrices are mostly like filter matrices above a certain threshold, find all the matrix indexes that are above some value, Find a list of values above say X and then find consecutive differences between them, some string replace manipulations. Do matrix dot products etc. I need to access thousands of files to generate these matrices(dlmread I use in MATLAB).

现在我需要以通常与操作系统(例如Perl,c或python或开源语言)捆绑在一起的任何其他语言来实现上述项目.

Now I am in need to implement the above project in any other language that are usually bundled with an OS say Perl, c or python or opensource language.

我做了一个简短的搜索,发现python是一个很好的研究工具. python是否有一些与MATLAB等效的矩阵运算(例如,将文件直接读入数组,查找,dlmwrite等)

I did a brief search and found out that python is a good tool for research. Does python has some of these MATLAB equivalents for matrix operations ( like read a file directly into an array, find, dlmwrite etc )

因为没有这些MATLAB函数,我的代码已经有很多循环,所以这些代码将变得更加混乱且难以维护.

Because my codes already have a lot of loops without these MATLAB functions the codes would get much messier and difficult to maintain.

或者您可以指出其他任何替代方法.我熟悉一点Perl,但不熟悉python或R.

Or could you point out any other alternatives. I am familiar with little Perl but not python or R.

推荐答案

此页比较NumPy和Matlab .

以下是有关您的帖子的一些示例:

Here are some examples regarding your post:

In [5]: import scipy

In [6]: X = scipy.randn(3,3)

In [7]: X
Out[7]: 
array([[-1.16525755,  0.04875437, -0.91006082],
       [ 0.00703527,  0.21585977,  0.75102583],
       [ 1.12739755,  1.12907917, -2.02611163]])

In [8]: X>0
Out[8]: 
array([[False,  True, False],
       [ True,  True,  True],
       [ True,  True, False]], dtype=bool)

In [9]: scipy.where(X>0)
Out[9]: (array([0, 1, 1, 1, 2, 2]), array([1, 0, 1, 2, 0, 1]))

In [10]: X[X>0] = 99

In [11]: X
Out[11]: 
array([[ -1.16525755,  99.        ,  -0.91006082],
       [ 99.        ,  99.        ,  99.        ],
       [ 99.        ,  99.        ,  -2.02611163]])

In [12]: Y = scipy.randn(3,2)

In [13]: scipy.dot(X, Y)
Out[13]: 
array([[-124.41803568,  118.42995937],
       [-368.08354405,  199.67131528],
       [-190.13730231,  161.54715769]])

(无耻的插件:我曾经在Python和Matlab之间进行的比较.)

这篇关于python是否能够执行MATLAB等效矩阵运算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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