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)
上一篇 2021年11月21日 下午3:00
下一篇 2021年11月21日 下午4:00


相关推荐

  • (RegionProposal Network)RPN网络结构及详解[通俗易懂]

    (RegionProposal Network)RPN网络结构及详解[通俗易懂]RPN(RegionProposalNetwork)区域生成网络Faster-RCNN的核心。在这里整理。1.anchors。特征可以看做一个尺度51*39的256通道图像,对于该图像的每一个位置,考虑9个可能的候选窗口:三种面积{128,256,512}×{128,256,512}×三种比例{1:1,1:2,2:1}{1:1,1:2,2:1}。这些候选窗口称为anchors…

    2022年6月23日
    116
  • new和malloc的作用是一样的_商城面试题

    new和malloc的作用是一样的_商城面试题new和malloc的区别是C/C++一道经典的面试题,我也遇到过几次,回答的都不是很好,今天特意整理了一下。0.      属性new/delete是C++关键字,需要编译器支持。malloc/free是库函数,需要头文件支持。1.      参数使用new操作符申请内存分配时无须指定内存块的大小,编译器会根据类型信息自行计算。而malloc则需要显式地指出所需内存的尺寸。

    2022年4月20日
    41
  • pycharm安装程序包_Python不可以安装的软件包

    pycharm安装程序包_Python不可以安装的软件包(1)命令行安装pipinstallXXX或者condainstallXXXXXX为包的名称,命令输入的位置如下图所示(两个均可使用,如果一个安装失败则使用另一个)(2)操作界面安装(i)依次点击file——settings,出现如下界面(2)点击图中+,出现如下界面,在搜索框中输入相应的包的名称,选中后点击installPackage(3)直接根据提示安装打开一个python源程序,在下面画有红色波浪线的均为未安装的包,将光标移动至红色波浪线处,会出现installp

    2022年8月29日
    8
  • matlab读.h5文件「建议收藏」

    matlab读.h5文件「建议收藏」之前用python给nuswide提取了VGG19特征,因为文件太大,超过.mat限制,存成.h5,见[1]。现在一个matlab程序要读,可以用h5disp查看.h5文件内容的结构(各个datasets),然后用h5read读。注意两点:文件名的类型要是char而不能是string,否则报错好像被自动转置了一次?我当初存的时候应该是n×dn\timesdn×d的,但读出来的时候变成d×nd\timesnd×n了(不知道是h5py[1]在存

    2025年9月4日
    6
  • n8n保姆级教程:10分钟搭建一个自动推送新闻机器人

    n8n保姆级教程:10分钟搭建一个自动推送新闻机器人

    2026年3月15日
    2
  • PCA降维算法总结以及matlab实现PCA(个人的一点理解)

    PCA降维算法总结以及matlab实现PCA(个人的一点理解)PCA的一些基本资料最近因为最人脸表情识别,提取的gabor特征太多了,所以需要用PCA进行对提取的特征进行降维。本来最早的时候我没有打算对提取的gabor特征进行降维,但是如果一个图像时64*64,那么使用五个尺度八个方向的gabor滤波器进行滤波,这样提取的特征足足有64*64*5*8这么多,如果图像稍微大一点,比如12

    2025年7月25日
    5

发表回复

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

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