Python中的Matlab结构

2024-04-25 05:26:49 发布

您现在位置:Python中文网/ 问答频道 /正文

python中是否有类似于Matlab结构的变量?在

我想在另一个结构中创建一个结构,就像在Matlab中一样,但是在Python中。 我查看了Python字典,但没有找到一种访问其值的简单方法。这在Matlab中非常简单。在

在Matlab中,我将执行以下操作:

创建结构

structure.parent1.variable1 = 23;
structure.parent1.variable2 = 19;
structure.parent1.variable3 = 19;
structure.parent2.variable1 = 10;
structure.parent2.variable2 = 11;

structure = 

    parent1: [1x1 struct]
    parent2: [1x1 struct]

然后直接访问变量tipying

^{pr2}$

Tags: 方法字典structure结构structmatlabvariable1pr2
2条回答

python中的字典有什么问题-创建并访问它们:

structure = {}
structure["parent1"] = {}
structure["parent1"]["variable1"] = 23;
structure["parent1"]["variable2"] = 19;
structure["parent1"]["variable3"] = 19;
structure["parent2"] = {}
structure["parent2"]["variable1"] = 10;
structure["parent2"]["variable2"] = 11;

使用字典可以访问这样的元素

structure['parent2']['variable1']

相关问题 更多 >