Calling Matlab function from python: “initializer must be a rectangular nested sequence”

Calling Matlab function from python: “initializer must be a rectangular nested sequence”

I am writing a python script from which I hope to call the Matlab anovan function. I have attempted a basic test of this feature on file test.txt.

This file is imported as array data. In matlab, the anovan function would be called as follows:

anovan(data(:,1),{data(:,2),data(:,3)})

In python, I have attempted to call the function like this:

import matlab.engine eng = matlab.engine.start_matlab() data = np.genfromtxt('test.txt') eng.anovan(matlab.double(data[:,0]),matlab.int8(data[:,1:2]))

Unfortunately, this gives the following error:

ValueError: initializer must be a rectangular nested sequence

I can see that there is some issue in passing the last two array columns to the function, but am unsure of the solution. Any suggestions would be appreciated.


 

I have now worked this out. The issue was in the format of the data passed to the function.

#convert grouping columns to integer lists list1 = data[:,1].tolist() for i in range(0,len(list1)): list1[i] = int(list1[i]) list2 = data[:,2].tolist() for i in range(0,len(list2)): list2[i] = int(list2[i]) #The following command now works eng.anovan(matlab.double(data[:,0].tolist()),[matlab.int8(list1),matlab.int8(list2)])
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/119595.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号