【发布时间】:2023-02-03 08:36:14
【问题描述】:
我有一个 numpy 数组 tuples:
import numpy as np
the_tuples = np.array([(1, 4), (7, 8)], dtype=[('f0', '<i4'), ('f1', '<i4')])
我想要一个 2D numpy 数组来代替:
the_2Darray = np.array([[1,4],[7,8]])
我试过做几件事,比如
import numpy as np
the_tuples = np.array([(1, 4), (7, 8)], dtype=[('f0', '<i4'), ('f1', '<i4')])
the_2Darray = np.array([*the_tuples])
我怎样才能转换它?
【问题讨论】:
-
np.array([list(item) for item in the_tuples])