Passing Python function input arguments from Matlab

11 ビュー (過去 30 日間)
Chandra Sekhar Kommineni
Chandra Sekhar Kommineni 2022 年 9 月 21 日
回答済み: Al Danial 2022 年 10 月 4 日
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('arrivaquant.py'));
if count(py.sys.path,arrival_time) == 0
insert(py.sys.path,int32(0),arrival_time);
end
%%
AT1_ms=data2(:,2);
TT1_us=data2(:,3);
LDV1_mps=-data2(:,4);
%%
%acfspc(t,u,w,dt,K2,meanrem=True,atw=False,locnor=False,selfproducts=False):
% 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
mod=py.importlib.import_module('arrivaquant');
py.importlib.reload(mod);
%% %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,

採用された回答

Al Danial
Al Danial 2022 年 10 月 4 日
Wrap your MATLAB matrices with py.numpy.array() instead of py.numpy.ndarray() in your call.
  1 件のコメント
Chandra Sekhar Kommineni
Chandra Sekhar Kommineni 2022 年 10 月 4 日
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.

サインインしてコメントする。

その他の回答 (1 件)

Al Danial
Al Danial 2022 年 10 月 4 日
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.

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by