Matlab to Python: can only pass 1xN vectors!

Note that for Matlab R2014b and newer calling Python, you can only send to Python a 1xN vector. You have to reshape the matrix into a 1xN vector when passing the matrix into Python, and reshape back to a matrix inside Python, involving memory copies at both Matlab reshapings.

Here is an example of calling Python from Matlab for image processing

Note that Numpy ndarrays are not understandable by Matlab, you will have to make your Numpy array into a 1-D list and then send it back. That’s a lot of memory copying!

I can pass





ans=[ 1.41421356  1.41421356]

but I cannot pass


Error using py.numpy.sqrt  Conversion of MATLAB 'double' to Python is only supported for 1-N vectors.

Mathworks confirms that you cannot pass normal 2D matrices to Python from Matlab

Leave a Comment