MATLAB: Convert matlab zeros function to Python equivalent

matlab python

Hi Could you pleas elet me know what would be a similar conversion of matlab zeros to np.zeros for datatype. I am getting an error while doing this.
Matlab code:
Shifts = zeros(length(Filters)-1,1,'int16');
Python code:
Shifts = np.zeros(len(Filters)-1,1,dtype = np.int16)

Best Answer

You need to read the numpy zeros documentation, because your syntax does not actually match its specification:
import numpy as np
Filters = [1,2,3];
Shifts = np.zeros((len(Filters)-1,1),dtype=np.int16)
% ^ ^ The shape needs to be ONE iterable!
Most likely you do not need a 2D numpy array, and a simple 1D array would suffice:
Shifts = np.zeros(len(Filters)-1,dtype=np.int16)
Related Question