矩阵运算 python matlab,python是否能够执行MATLAB等效矩阵运算?

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).

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.

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 )

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

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

解决方案

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]])

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值