I want to call some python code from MATLAB, in order to do this I need to convert a matrix object to a NumPy ndarray
, through the MATLAB function py.numpy.array
. However, passing simply the matrix object to the function does not work. At the moment I solved the problem converting the matrix to a cell of cells object, containing the rows of the matrix. For example
function ndarray = convert(mat)
% This conversion fails
ndarray = py.numpy.array(mat)
% This conversion works
cstr = cell(1, size(mat, 1));
for row = 1:size(mat, 1)
cstr(row) = {mat(row, :)};
end
ndarray = py.numpy.array(cstr);
I was wondering if it exists some more efficient solution.
1XN
Infile.py
convert it to a numpy ndarray. – Tony TannousMxN
ndarray
. – aretor