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)])
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

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

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 下标「建议收藏」

    下标「建议收藏」下标下标可以定义在类、结构体和枚举中,是访问集合、列表或序列中元素的快捷方式。可以使用下标的索引,设置和获取值,而不需要再调用对应的存取方法。举例来说,用下标访问一个Array实例中的元素可以写

    2022年8月3日
    6
  • bytebuf详解_byte int

    bytebuf详解_byte int@author鲁伟林记录《Netty实战》中各章节学习过程,写下一些自己的思考和总结,帮助使用Netty框架的开发技术人员们,能够有所得,避免踩坑。本博客目录结构将严格按照书本《Netty实战》,省略与Netty无关的内容,可能出现跳小章节。本博客中涉及的完整代码:GitHub地址:https://github.com/thinkingfioa/netty-learning/tre…

    2022年9月19日
    4
  • Linux相关操作

    Linux相关操作

    2021年7月7日
    86
  • 无锁编程 汇总

    无锁编程 汇总无锁编程主要是通过一系列原子操作实现。原子操作:1.  Read-Modify-Write(RMW)操作Win32上的_InterlockedIncrementandInterlockedDecrement,iOS上的OSAtomicAdd32以及C++11中的std::atomic::fetch_add。需要注意的是,C++11的原子标准不保证其在每个平台上的实现都是无

    2022年5月31日
    39
  • 1156针cpu排行_755针最强CPU

    1156针cpu排行_755针最强CPUIntel酷睿i7875K¥2330CPU主频:2930MHz智能加速:3600MHz插槽类型:LGA1156制作工艺:45纳米二级缓存:4×256KB三级缓存:8M核心数量:四核心核心类型:Lynnfield线程数:八线程总线类型:DMI总线热设计功耗(TDP):95W内核电压:0.65-1.40V内存控制器:双通道DDR3-1066/1333最大16G64位处理器。…

    2022年9月20日
    1

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

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