Azzera filtri
Azzera filtri

Passing Python function input arguments from Matlab

7 visualizzazioni (ultimi 30 giorni)
Hello all,
I'm trying to use external python libraries in side matlab, but I'm facing some problems in passing array of size 100k. Python is not accepting ndarray. I'm not sure, how to pass the input arguments, can someone explain what I'm doing wrong. Thank you, Here is my matlab code,mat file and python code attached.
clear all;
arrival_time = fileparts(which(''));
if count(py.sys.path,arrival_time) == 0
% t: array of real values, random arrival times (single block
% # or whole LDV data set)
% # u: array of real or complex values, velocities (single block
% # or whole LDV data set)
% # w: array of real values, individual weights (single block
% # or whole LDV data set), e.g. transit times, not used if
% # atw==True)
% # dt: real value, fundamental time step, e.g. temporal resolution
% # of the correlation function
% # K2: positive integer, maximum lag time in the estimated correlation
% # function in units of dt, yields a correlation function estimated
% # for lag times from -K2*dt to K2*dt (
%pyOut = py.arrivaltime_quantization.acfspc(t,u,w,dt,K2,meanrem=True,atw=False,locnor=False,selfproducts=False);
fs= 1e3/mean(diff(AT1_ms));
dt1_ms= 1/fs; %fs=mean data rate
%clear classes
%% %pyOut = py.arrivaltime_quantization.acfspc(t,u,w,dt,K2,meanrem=True,atw=False,locnor=False,selfproducts=False);
[test,t,x,c] = py.arrivaquant.acfspc(py.numpy.ndarray(AT1_ms),py.numpy.ndarray(LDV1_mps),py.numpy.ndarray(TT1_us),dt1_ms,6000,meanrem=py.bool('True'),atw=py.bool('True'),locnor=py.bool('True'),selfproducts=py.bool('True'));
I'm getting following error, Python Error: ValueError: maximum supported dimension for an ndarray is 32, found 109156
Please let me know what i'm doing wrong here. Thank you so much in advance,

Risposta accettata

Al Danial
Al Danial il 4 Ott 2022
Wrap your MATLAB matrices with py.numpy.array() instead of py.numpy.ndarray() in your call.
  1 Commento
Chandra Sekhar Kommineni
Chandra Sekhar Kommineni il 4 Ott 2022
Hello Al Danial,
Yes, I tried this one before and worked. python is not accepting matlab arrays and even integers also, I changed to python input format.
anyway thank you so much your answer.

Accedi per commentare.

Più risposte (1)

Al Danial
Al Danial il 4 Ott 2022
Integers are tricky because what looks like an integer in MATLAB is actually a double unless you explicitly cast it, for example with int64(). As you noted, this causes problems for Python which will reject a double in many cases. I talk about this exact case in my presentation at the 2022 MATLAB Expo.




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by