我在PYTHON中有这种格式的json数组。如何使它成为2d numpy数组?
[{"z":1,"y":0.10000000149011612,"x":0.10000000149011612},{"z":0.6666666865348816,"y":0.10000000149011612,"x":0.20000000298023224},{"z":0.5,"y":0.10000000149011612,"x":0.30000001192092896},{"z":0.6666666865348816,"y":0.10000000149011612,"x":0.4000000059604645},{"z":0.3333333432674408,"y":0.10000000149011612,"x":0.5},{"z":0.1666666716337204,"y":0.10000000149011612,"x":0.6000000238418579},{"z":0.8333333134651184,"y":0.10000000149011612,"x":0.699999988079071},{"z":0.5,"y":0.10000000149011612,"x":0.800000011920929},{"z":0.5,"y":0.25999999046325684,"x":0.10000000149011612},{"z":0.5,"y":0.25999999046325684,"x":0.20000000298023224},{"z":1,"y":0.25999999046325684,"x":0.30000001192092896},{"z":0.1666666716337204,"y":0.25999999046325684,"x":0.4000000059604645},{"z":0.1666666716337204,"y":0.25999999046325684,"x":0.5},{"z":0.5,"y":0.25999999046325684,"x":0.6000000238418579},{"z":0.8333333134651184,"y":0.25999999046325684,"x":0.699999988079071},{"z":0.6666666865348816,"y":0.25999999046325684,"x":0.800000011920929},{"z":0.5,"y":0.41999998688697815,"x":0.10000000149011612},{"z":0.6666666865348816,"y":0.41999998688697815,"x":0.20000000298023224},{"z":0.1666666716337204,"y":0.41999998688697815,"x":0.30000001192092896},{"z":0.6666666865348816,"y":0.41999998688697815,"x":0.4000000059604645},{"z":0.5,"y":0.41999998688697815,"x":0.5},{"z":0.8333333134651184,"y":0.41999998688697815,"x":0.6000000238418579},{"z":0.8333333134651184,"y":0.41999998688697815,"x":0.699999988079071},{"z":0.5,"y":0.41999998688697815,"x":0.800000011920929},{"z":0.6666666865348816,"y":0.5799999833106995,"x":0.10000000149011612},{"z":0.6666666865348816,"y":0.5799999833106995,"x":0.20000000298023224},{"z":0.1666666716337204,"y":0.5799999833106995,"x":0.30000001192092896},{"z":0.1666666716337204,"y":0.5799999833106995,"x":0.4000000059604645},{"z":0.8333333134651184,"y":0.5799999833106995,"x":0.5},{"z":0.5,"y":0.5799999833106995,"x":0.6000000238418579},{"z":0.6666666865348816,"y":0.5799999833106995,"x":0.699999988079071},{"z":0.1666666716337204,"y":0.5799999833106995,"x":0.800000011920929},{"z":0.3333333432674408,"y":0.7400000095367432,"x":0.10000000149011612},{"z":1,"y":0.7400000095367432,"x":0.20000000298023224},{"z":0.1666666716337204,"y":0.7400000095367432,"x":0.30000001192092896},{"z":0.3333333432674408,"y":0.7400000095367432,"x":0.4000000059604645},{"z":1,"y":0.7400000095367432,"x":0.5},{"z":0.1666666716337204,"y":0.7400000095367432,"x":0.6000000238418579},{"z":0.1666666716337204,"y":0.7400000095367432,"x":0.699999988079071},{"z":0.1666666716337204,"y":0.7400000095367432,"x":0.800000011920929}]
数组看起来像:([[1,2,3],[4,5,6]])
每个json对象都是[]
答案 0 :(得分:2)
据我所知,json_array是词典列表
m = np.zeros((len(json_aaray), 3))
for i, elem in enumerate(json_array):
m[i,0] = elem['x']
m[i,1] = elem['y']
m[i,2] = elem['z']