【发布时间】:2021-05-08 01:34:51
【问题描述】:
假设我有一个字典数组:
thisdict={}
thisdict[0]={1: 'one', 2: "two"}
thisdict[1]={3: 'three', 4:'four'}
thisdict[2]={5: 'five', 6:'six'}
我怎样才能找到它的尺寸?我正在寻找 (3,2) -- 3 个字典,每个有 2 个条目。
len(thisdict) 产生 3。
np.shape(thisdict)返回()
和
np.size(thisdict) 返回 1。
如果我通过
将字典转换为数据框import pandas as pd
tmp = pd.DataFrame.from_dict(thisdict)
那么,
np.size(tmp) = 18
和
np.shape(tmp) =(6,3)
因为 时间=
这仍然没有给我我想要的东西。
我想我能做到
len(thisdict) 后跟
len(thisdict[0])
获得我感兴趣的两个维度,但我认为有更好的方法。获取这两个维度的“正确”方法是什么?
【问题讨论】:
-
是固定的条目长度吗?我的意思是
thisdict[0]可以有 2 个条目,但thisdict[1]可以有 3 个条目 -
谢谢。就我而言,是的 - 字典数组中的所有字典都具有相同数量的条目。
标签: python arrays dictionary shapes dimensions