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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • scrapy爬虫学习系列一:scrapy爬虫环境的准备

    scrapy爬虫学习系列一:scrapy爬虫环境的准备系列文章列表:scrapy爬虫学习系列一:scrapy爬虫环境的准备:http://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_python_007_scr

    2022年7月2日
    26
  • HTML5移动端手机网站开发流程

    HTML5移动端手机网站开发流程最近一直在研究移动手机网站的开发,发现做手机网站没有想象中的那么难。为什么会这么说呢?我们试想下:我们连传统的PC网站都会做,难道连一个小小的手机网站难道都搞不定吗?其实手机网站就是一个微缩版的PC网站罢了!至于为什么觉得难、觉得无从下手。段亮觉得有以下几点:一、没有完整的思路和流程就像做网站的流程一样,如果你能知道它的流程,我相信就不会觉得做手机网站难!真正难的是你没有思

    2022年6月21日
    23
  • CentOS7安装MySQL(完整版)

    CentOS7安装MySQL(完整版)在CentOS中默认安装有MariaDB,这个是MySQL的分支,但为了需要,还是要在系统中安装MySQL,而且安装完成之后可以直接覆盖掉MariaDB。1下载并安装MySQL官方的YumRepository[root@localhost~]#wget-i-chttp://dev.mysql.com/get/mysql57-community-release-…

    2022年4月28日
    30
  • mac上Latex的安装及使用教程「建议收藏」

    mac上Latex的安装及使用教程「建议收藏」latex的安装官网下载地址:http://tug.org/mactex/以前在Mac上装Tex/LaTeX很麻烦,现在容易多了,只需要下载单个软件包MacTeX.mpkg.zip即可,安装后会在Applications下生成一个Tex目录,Tex/LaTeX编辑器TeXShop,reference工具BibDesk,拼写检查工具Excalibur等都在这个目…

    2022年5月11日
    149
  • 查看 android打包证书签名

    查看 android打包证书签名查看android打包证书签名用javakeytool查看证书签名keytool-list-v-keystore证书路径输入证书密码之后会看到MD5\SHA1\SHA256签名。这里插一句题外话,有的平台需要的也是签名例如微信系列的直接把签名大写改成小写去掉冒号即可。…

    2022年6月7日
    34
  • 基于Docker的Kafka集群搭建

    基于Docker的Kafka集群搭建1.pulldocker,在机器上下载最新版本的kafka和zookeeper镜像,这里使用的是wurstmeister的镜像dockerpullwurstmeister/kafkadockerpullwurstmeister/zookeeper2.装好的docker镜像3.启动zk容器Dockerrun–d–namezookeeper–p2181:…

    2022年6月9日
    52

发表回复

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

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