MATLAB: Problem with python numpy

MATLABnumpynumpy frameworkpythonpython callpython in matlab

I have started to try to use python functionality in matlab. The Textwrapper example works. I now tried other packages, and everytime there is some dependency on numpy I get this message:
>> py.help('numpy')
problem in numpy - ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: DLL load failed: Das angegebene Modul wurde nicht gefunden.
If I try to use numpy directly, I get this:
>> x = py.numpy.random.random([4,4]);
Undefined variable "py" or class "py.numpy.random.random".
Calling
help('textwrap')
or
help('numpy')
in Python works fine. Calling
py.help('textwrap')
in Matlab works,
py.help('numpy')
does not.
I have tried to update numpy and to remove and reinstall it, but this does nothing. I am using Python 3.6 which should be supported.
>> pyversion
version: '3.6'
executable: 'C:\ProgramData\Anaconda3\python.exe'
library: 'C:\ProgramData\Anaconda3\python36.dll'
home: 'C:\ProgramData\Anaconda3'
isloaded: 1
Maybe I am doing something wrong?

Best Answer

Beginning in MATLAB R2018b, Python functions that accept numpy arrays may also accept MATLAB arrays without explicit conversion. When necessary, a numpy array can be created explicitly from a MATLAB array. For example, if you have a supported version of Python that is installed with the numpy library, you can do the following:
>> x = rand(2,2); % MATLAB array
>> y = py.numpy.array(x); % numpy array
y =
Python ndarray:
0.5943 0.8064
0.6133 0.1372
Use details function to view the properties of the Python object.
Use double function to convert to a MATLAB array.
Also beginning in MATLAB R2018b, it is possible to convert numeric numpy arrays returned from Python into MATLAB arrays. For example:
>> y = py.numpy.random.random([int32(2), int32(2)]) % numpy array
y =
Python ndarray:
0.5943 0.8064
0.6133 0.1372
Use details function to view the properties of the Python object.
Use double function to convert to a MATLAB array.
>> x = 2*double(y) % MATLAB array
x =
1.1885 1.6129
1.2266 0.2744
See the MATLAB documentation on Passing Matrices and Multidimensional Arrays for additional Information.