Equivalent Matlab function
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? Matthieu -- Information System Engineer, Ph.D. Blog: http://matt.eifelle.com LinkedIn: http://www.linkedin.com/in/matthieubrucher
On Thu, Sep 2, 2010 at 3:56 AM, Matthieu Brucher
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
Thanks Joseph, I'll wrap this inside my code ;)
Matthieu
2010/9/2
On Thu, Sep 2, 2010 at 3:56 AM, Matthieu Brucher
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
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@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
participants (2)
-
josef.pktd@gmail.com
-
Matthieu Brucher