필터 지우기
필터 지우기

Passing Python function input arguments from Matlab

조회 수: 8 (최근 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.

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by