Python字典,列表,元组,字符的长度用len()函数,矩阵的长度用shape

如果需要知道某数据类型的长度或维度,
先 print type(xxx)知道数据类型,例如读取json文件
[{“keypoints”: [ 677.9600219726562, 739.485595703125, 0.004566059447824955, 664.0691528320312, 747.8201293945312, 0.004143653437495232], “score”: 2.6802735328674316, “image_id”: “00500.jpg”, “category_id”: 1}, {“keypoints”: [ 456.440185546875, 1005.5248413085938, 0.0018323599360883236, 260.51141357421875, 846.6636352539062, 0.006010023411363363, 255.2160186767578, 1002.8771362304688, 0.004762142430990934], “score”: 2.4920735359191895, “image_id”: “00500.jpg”, “category_id”: 1}]

f = open("./3/alphapose-results.json", encoding='utf-8')  
setting = json.load(f)
print(type(setting))

print(len(setting))
2

对于另一个json文件:
{“keypoints”: [ 677.9600219726562, 739.485595703125, 0.004566059447824955, 664.0691528320312, 747.8201293945312, 0.004143653437495232], “score”: 2.6802735328674316, “image_id”: “00500.jpg”, “category_id”: 1}

f = open("./3/alphapose-results.json", encoding='utf-8')  
setting = json.load(f)
print(type(setting))

print(len(setting))
4


你可能感兴趣的:(json,python)