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)])
Calling Matlab function from python: “initializer must be a rectangular nested sequence”的更多相关文章
- Libsvm:脚本(subset.py、grid.py、checkdata.py) | MATLAB/OCTAVE interface | Python interface
1.脚本 This directory includes some useful codes: 1. subset selection tools. (子集抽取工具) subset.py 2. par ...
- Python的扩展接口[3] -> Matlab引擎 -> 使用 Python 调用 Matlab 程序
Python - Matlab 目录 Python-Matlab 引擎 Python-Matlab 数组 Python-Matlab 基本操作 Python-Matlab 调用 m 文件 Matlab ...
- initialize myObject by calling a function that returns an object literal
w作用域控制变量的可见范围. JavaScript: The Good Parts Instead of initializing myObject with an object literal, w ...
- [CentOS Server] Bug when calling matlab in bash
尝试了好几遍,仍然不能用简写命令调用matlab,这里把过程记录如下. (1). 登录 server [She@She ~]$ ssh shecl@xx.xx.xx.xx Last :: from x ...
- Matlab function lorenzgui
function lorenzgui %LORENZGUI Plot the orbit around the Lorenz chaotic attractor. % This function an ...
- TypeError: 'encoding' is an invalid keyword argument for this function 解决Python 2.7
在python2.7中这样调用代码 open('file/name.txt','r',encoding= 'utf-8').read() 会出现 TypeError: 'encoding' is an ...
- 解决方法:loadrunner 场景下执行webservice脚本是---报错10492 Error: Exception was raised when calling per-process-init function in extens
在vug下执行时,脚本无异常,但是在controller下执行时报下面错误,网上查了下,解决方法千奇百怪,但无一可行. 分析了下错误,似乎是初始化进程有关.想到rts中的设置习惯时以线程方式执行. 遂 ...
- [Python-MATLAB] 在Python中调用MATLAB的API
可以参考官方的说明文档: http://cn.mathworks.com/help/matlab/matlab_external/get-started-with-matlab-engine-for- ...
- Python调用Matlab2014b引擎
用惯Python的你,是不是早已无法忍受matplotlib那丑陋无比的图以及蛋疼无比部署依赖? 当当当当,Matlab2014b的Python Engine API现已加入豪华午餐. 上次写了一篇文 ...
随机推荐
- 高手速成android开源项目【developer篇】
主要介绍和Android开发工具和测试工具相关的开源项目. Buckfacebook开源的Android编译工具,效率是ant的两倍.主要优点在于:(1) 加快编译速度,通过并行利用多核cpu和跟踪不 ...
- koa执行过程原理分析
本文原创,转载请注明出处https://i.cnblogs.com/EditPosts.aspx?postid=5710639 我们大家都知道,当koa接到请求经过中间件时,当执行到 yield ne ...
- java中打印实心菱形以及空心菱形的方法
一.打印效果 二.实现代码汇总 为了方便初学者对代码的理解,建议熟练t1到t5为各种三角的打印,然后再进行菱形的打印实现. package circulationDemo; import java.u ...
- WINDOWS内核编程(一)Hello Drv的实现
我们开始编写第一个驱动程序,首先我们需要进行项目的创建,在以前的随笔中,我们已经学会了如何去建立双机调试环境. 我们打开VS2017,建立如图所示的项目,取名为:MyFirstDriver.点击确定 ...
- leetcode — median-of-two-sorted-arrays
import java.util.HashSet; import java.util.Set; /** * Source : https://oj.leetcode.com/problems/long ...
- GNU μC/OS-II 在 S3C2440 上中断的实现
上一篇文章介绍了S3c2440的中断体系结构,今天我们来分析一下GNU-uC/OS-II在S3c2440上中断的实现. 首先找到IRQ的中断的向量,位于 2440init.S : OK ,我们通过名字 ...
- IdentityServer4 中文文档 -5- (简介)支持和咨询选项
IdentityServer4 中文文档 -5- (简介)支持和咨询选项 原文:http://docs.identityserver.io/en/release/intro/support.html ...
- [转]Oracle密码过期, 报:ORA-01017: 用户名/口令无效; 登录被拒绝
本文转自:https://blog.csdn.net/jeff06143132/article/details/25696371 连接Oracle,以Oracle用户登陆: $su - oracl ...
- SQL Where in (1,2,3,4) 换成字段一列的值
) ; , ) ) FROM r_resource WHERE id IN ( @resource) 换成 ) : , ) ) FROM r_resource )) SELECT cid,id FRO ...
- 服务器CPU居高不下--解决问题历程
基本的概述 在一个服务器的集群上面,服务器的CPU长时间居高不下,响应的时间也一直很慢,即使扩容了服务器CPU的下降效果也不是很明显. 对于CPU过高的原因,可以总结到以下原因: 太多的循环或者死循环 ...