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现已加入豪华午餐. 上次写了一篇文 ...
随机推荐
- LDA-线性判别分析(一)预备知识
本来是要调研 Latent Dirichlet Allocation 的那个 LDA 的, 没想到查到很多关于 Linear Discriminant Analysis 这个 LDA 的资料.初步看了 ...
- 04-TypeScript中的方法新功能(上)
在TypeScript中,提供了一些函数的新功能,能够简化JavaScript中的一些比较复杂代码才能实现的一些能力. 在C#后端语言中,能够对方法传递的参数指定params关键字,也就是可以传递任意 ...
- 7.28-说说对javaweb的感想吧
接触了几个月的java,和javaweb. 感想1:发现生活顿时充实了很多,时间照样在过,日落日出,但是手里面有学的,有可以让自己开心地码出理想的效果,这是很不错的结局. 发现自己再也不回去和伙伴们撸 ...
- 深入理解String, StringBuffer, StringBuilder的区别(基于JDK1.8)
String.StringBuffer.StringBuilder都是JAVA中常用的字符串操作类,对于他们的区别大家也都能耳熟能详,但底层到底是怎样实现的呢?今天就再深入分析下这三种字符串操作的区别 ...
- Elasticsearch从入门到精通之Elasticsearch基本概念
导读 在上一章节我们介绍Elasticsearch前世今生,今天我们继续进行本章内容,Elasticsearch的核心概念.从一开始就理解这些概念将极大地帮助简化学习过程. 近实时(NRT) Elas ...
- 【PyTorch深度学习60分钟快速入门 】Part2:Autograd自动化微分
在PyTorch中,集中于所有神经网络的是autograd包.首先,我们简要地看一下此工具包,然后我们将训练第一个神经网络. autograd包为张量的所有操作提供了自动微分.它是一个运行式定义的 ...
- JavaWeb学习 (二十四)————Filter(过滤器)常见应用
一.统一全站字符编码 通过配置参数charset指明使用何种字符编码,以处理Html Form请求参数的中文问题 1 package me.gacl.web.filter; 2 3 import ja ...
- SpringMVC入门学习(一)
SpringMVC入门学习(一) ssm框架 spring SpringMVC是一个Java WEB框架,现在我们知道Spring了,那么,何为MVC呢? MVC是一种设计模式,其分为3个方面 mo ...
- VB.NET语法小结
本人精通C#编程,VB没有开发经验,项目维护需要,特意整理了下VB语法,进行恶补.编程思想都是互通的,都是微软生的,语言大同小异. Imports System 一.(1)定义一个变量,并且初始化. ...
- 5.数码相框-额外项目电子书总结,并使用svgalib库
在LCD显示任意编码的文本文件,类似电子书 怎样在LCD上显示文件: 需要哪几个文件? 1.顶部文件 通过main.c分析命令行的操作,然后初始化各个管理文件下的结构体,比如DisplayInit() ...