Python Forum
Convolution "same" in Python doesn't work as Matlab
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Convolution "same" in Python doesn't work as Matlab
#1
Hello, I'm trying to replicate Matlab's convolution aka conv function.

Matlab's conv works like this:

Quote:w = conv(u,v,shape) returns a subsection of the convolution, as specified by shape. For example, conv(u,v,'same') returns only the central part of the convolution, the same size as u.

I tried numpy convolve but documentation says it work differently, in fact:

numpy.convolve(a, v, mode) where:
- a(N,) array_like
- v(M,) array_like
- mode{‘full’, ‘valid’, ‘same’}

but the problem is that 'same' does NOT work as Matlab, in fact it says

Quote:Mode ‘same’ returns output of length max(M, N).

But I don't want the output to be of length max(M,N)!!! I want it to be same size as u as Matlab's.

Any idea how to do that?
Reply


Messages In This Thread
Convolution "same" in Python doesn't work as Matlab - by claw91 - Sep-30-2020, 09:05 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem of converting Matlab code to python DongyanZ 2 1,421 Feb-03-2023, 01:04 PM
Last Post: jefsummers
  Numpy doesn't work in Spyder 4.1.3 player1681 1 2,159 Jun-02-2020, 11:26 AM
Last Post: jefsummers
  Python equivalent of Matlab code kwokmaster 5 7,109 Apr-03-2020, 12:02 AM
Last Post: scidam
  scipy interp2d doesn't work player1681 4 4,514 Feb-05-2020, 09:50 AM
Last Post: player1681
  Is there similar function to lsqnonlin (in matlab) in python? Jay_Nerella 1 5,971 Nov-11-2019, 08:40 AM
Last Post: feli_x
  Matlab to Python Ariane 6 7,097 Jun-14-2018, 12:08 PM
Last Post: Ariane
  How to use .m matlab file in python ? sameer 5 15,406 May-10-2018, 09:39 AM
Last Post: wavic
  cx_Freeze doesn't seem to work owenwalker65 7 16,869 Dec-07-2017, 02:23 AM
Last Post: issac_n
  Importing matlab cell array (.mat) into a python list scanato 0 8,677 Nov-15-2017, 11:04 AM
Last Post: scanato
  Numpy or Scipy Variance Convolution TimWebPhoenix 0 3,362 Jul-11-2017, 12:41 PM
Last Post: TimWebPhoenix

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020