Is Python Capable Of Doing Matlab Equivalent Matrix Operations?
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 filt
Solution 1:
Start with this page comparing NumPy and 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]])
(Shameless plug: a comparison I once made between Python and Matlab.)
Post a Comment for "Is Python Capable Of Doing Matlab Equivalent Matrix Operations?"