[Numpy-discussion] Equivalent Matlab function

Matthieu Brucher matthieu.brucher at gmail.com
Thu Sep 2 13:05:26 EDT 2010


Thanks Joseph, I'll wrap this inside my code ;)

Matthieu

2010/9/2  <josef.pktd at gmail.com>:
> On Thu, Sep 2, 2010 at 3:56 AM, Matthieu Brucher
> <matthieu.brucher at gmail.com> wrote:
>> Hi,
>>
>> I'm looking for a Numpy equivalent of convmtx
>> (http://www.mathworks.in/access/helpdesk/help/toolbox/signal/convmtx.html).
>> Is there something inside Numpy directly? or perhaps Scipy?
>
> I haven't seen it in numpy or scipy, but I have seen something similar
> in a PDE or FEM package.
>
> Using the toeplitz hint from the matlab help, the following seems to
> work, at least in the examples
>
>>>> from scipy import linalg
>
>>>> h = np.array([1,3,1])
>>>> nc = 10; nr = nc-len(h)+1
>>>> linalg.toeplitz(np.r_[[1],np.zeros(nr-1)], np.r_[h,np.zeros(nc-len(h))])
> array([[ 1.,  3.,  1.,  0.,  0.,  0.,  0.,  0.,  0.,  0.],
>       [ 0.,  1.,  3.,  1.,  0.,  0.,  0.,  0.,  0.,  0.],
>       [ 0.,  0.,  1.,  3.,  1.,  0.,  0.,  0.,  0.,  0.],
>       [ 0.,  0.,  0.,  1.,  3.,  1.,  0.,  0.,  0.,  0.],
>       [ 0.,  0.,  0.,  0.,  1.,  3.,  1.,  0.,  0.,  0.],
>       [ 0.,  0.,  0.,  0.,  0.,  1.,  3.,  1.,  0.,  0.],
>       [ 0.,  0.,  0.,  0.,  0.,  0.,  1.,  3.,  1.,  0.],
>       [ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  1.,  3.,  1.]])
>
>>>> h = np.array([1,2,3,2,1])
>>>> nc = 10; nr = nc-len(h)+1
>>>> linalg.toeplitz(np.r_[[1],np.zeros(nr-1)], np.r_[h,np.zeros(nc-len(h))])
> array([[ 1.,  2.,  3.,  2.,  1.,  0.,  0.,  0.,  0.,  0.],
>       [ 0.,  1.,  2.,  3.,  2.,  1.,  0.,  0.,  0.,  0.],
>       [ 0.,  0.,  1.,  2.,  3.,  2.,  1.,  0.,  0.,  0.],
>       [ 0.,  0.,  0.,  1.,  2.,  3.,  2.,  1.,  0.,  0.],
>       [ 0.,  0.,  0.,  0.,  1.,  2.,  3.,  2.,  1.,  0.],
>       [ 0.,  0.,  0.,  0.,  0.,  1.,  2.,  3.,  2.,  1.]])
>
> maybe worth adding to the other special matrix improvements that Warren did.
>
> Josef
>
>>
>> Matthieu
>> --
>> Information System Engineer, Ph.D.
>> Blog: http://matt.eifelle.com
>> LinkedIn: http://www.linkedin.com/in/matthieubrucher
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at scipy.org
>> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
Information System Engineer, Ph.D.
Blog: http://matt.eifelle.com
LinkedIn: http://www.linkedin.com/in/matthieubrucher



More information about the NumPy-Discussion mailing list