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


相关推荐

  • leetcode394字符串解码(回溯|栈)「建议收藏」

    leetcode394字符串解码(回溯|栈)「建议收藏」给定一个经过编码的字符串,返回它解码后的字符串。编码规则为: k[encoded_string],表示其中方括号内部的 encoded_string 正好重复 k 次。注意 k 保证为正整数。你可以认为输入字符串总是有效的;输入字符串中没有额外的空格,且输入的方括号总是符合格式要求的。此外,你可以认为原始数据不包含数字,所有的数字只表示重复的次数 k ,例如不会出现像 3a 或 2[4] 的输入。示例 1:输入:s = “3[a]2[bc]”输出:”aaabcbc”示例 2:输入:s =

    2022年8月8日
    1
  • redhat6配置yum源_centos7yum源的配置

    redhat6配置yum源_centos7yum源的配置一、配置本地yum源首先将已连接和启动时连接勾选上将操作系统镜像上传到虚拟机(/root)上创建一个挂载目录mkdir-p/dvd/iso将iso镜像文件挂载到/dvd/isomount/root/rhel-server-7.0-x86_64-dvd.iso/dvd/iso查看状态df-Th然后进入/etc/yum.repo/创建一个文件并编辑(文件名可以随便,但后缀必须为.repo)vimdvd.repo[dvd]name=dvd..

    2022年8月13日
    11
  • redis如何设置密码及验证密码_无线密码忘记了怎么在手机上查看

    redis如何设置密码及验证密码_无线密码忘记了怎么在手机上查看一、前言对于redis而言,其并没有实现访问控制这个功能,但是可以提供一个轻量级的auth认证方式。可以通过编辑对应的redis配置文件。redis.conf来启动二、设置密码1、找到redis的配置文件redis.conf配置文件中的参数:requirepass,就是配置redis访问密码的参数;#默认情况下,是注释的requirepassxxxx;设置requirepass密码如下。2、然后需要重启下redis服务,才能生效#1、kill掉redis进程#2、启动re

    2022年9月6日
    2
  • DM368开发 — uboot、内核移植(转)「建议收藏」

    DM368开发 — uboot、内核移植(转)「建议收藏」参看:DAVINCIDM365-DM368开发攻略——U-BOOT-2010.12及UBL的移植参看:DAVINCIDM365-DM368开发攻略——linux-2.6.32的移植一、介绍u-boot-2010.12的特点u-boot-2010.12的架构组织越来越向LINUX架构靠拢,这是U-BOOT的发展趋势。DM36x的UBOOT源码放在dvsdk_dm368_4_02_00_06\ps

    2022年8月13日
    5
  • 怎样用Google APIs和Google的应用系统进行集成(1)—-Google APIs简介

    怎样用Google APIs和Google的应用系统进行集成(1)—-Google APIs简介

    2022年1月20日
    47
  • python基础(2)字符串常用方法[通俗易懂]

    python基础(2)字符串常用方法[通俗易懂]python字符串常用方法find(sub[,start[,end]])在索引start和end之间查找字符串sub​找到,则返回最左端的索引值,未找到,则返回-1​start和end都可

    2022年7月30日
    3

发表回复

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

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