[Numpy-discussion] Equivalent Matlab function

josef.pktd@gmai... josef.pktd@gmai...
Thu Sep 2 09:19:31 CDT 2010


On Thu, Sep 2, 2010 at 3:56 AM, Matthieu Brucher
<matthieu.brucher@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@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>


More information about the NumPy-Discussion mailing list