2
我一直在尝试使用ndarray的numpy ndarray来变换数组的数组。将数组变换为NumPy的ndarray中的示例
这是我的D型:
dt = 'i8,i8,i8,i8,i8,i8,i8,i8,i8,i8,i8,i8,i8,f8,i8,i8,f8,f8,f8,a50,a50,a50,a50'
这是我的数据:
# data array reduced to one row for sake of readability
data = [[45608L, 0L, 46115L, 11952L, 11952L, 0, 0, 0, 0, 0, 11951L, 11951L, 46176L, 9.0, 0, 1, 1407340577.0, 1407340577.0, 0, 'Simulation Movement', 'planned', '', ''],]
我已经尝试了这些方法:
np.array(data, dt)
np.array([np.array(row, dt) for row in data])
但是当我运行这两个我得到:
TypeError: expected a readable buffer object
Buuuuut,如果我叫np.array
以与阵列仅包含我行的每个单独的元件,并使用适当的数据类型(这样做是使用具有枚举回路和分裂dt
),它的工作原理。是这样的:
for row in data:
for index, value in enumerate(row):
np.array([value,], dt.split(',')[index])
任何想法,请?