Python中的Matlab结构 [英] Matlab structure in Python
本文介绍了Python中的Matlab结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
python中是否有类似于Matlab结构的变量?
Is there any variable in python similar to Matlab structures?
我想在另一个结构中创建一个结构,就像在Matlab中一样,但是在Python中. 我正在研究Python字典,但是还没有找到访问其值的简单方法.在Matlab中,这真的很容易.
I would like to create a structure within another structure as in Matlab, but in Python. I've looking into Python Dictionaries, but I have not find an easy way to access to its values. Which in Matlab is really easy.
在Matlab中,我将执行以下操作:
In Matlab I would do the following:
创建结构
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]
然后只需简单地访问变量即可
And then access to the variable simply tipying
structure.parent2.variable1
ans =
10
推荐答案
python中的字典有什么问题-创建然后访问它们:
what is wrong with dictionaries in python - to create and then access them :
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;
这篇关于Python中的Matlab结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文