的numpy manual提到了numpy.save如何构建嵌套numpy记录数组?
安妮分析师一直使用大型嵌套记录阵列代表 她的统计数据使用情况。
是否有可能嵌套记录数组没有dtype = object?如果是这样,怎么样?
的numpy manual提到了numpy.save如何构建嵌套numpy记录数组?
安妮分析师一直使用大型嵌套记录阵列代表 她的统计数据使用情况。
是否有可能嵌套记录数组没有dtype = object?如果是这样,怎么样?
您可以构造嵌套数组您构建嵌套列表以同样的方式:
nested_list = [['a',1],['b',2],['c',3]]
import numpy as np
nested_array = np.array(nested_list)
是的,就像这样:
engine_dt = np.dtype([('volume', float), ('cylinders', int)])
car_dt = np.dtype([('color', int, 3), ('engine', engine_dt)]) # nest the dtypes
cars = np.rec.array([
([255, 0, 0], (1.5, 8)),
([255, 0, 255], (5, 24)),
], dtype=car_dt)
print(cars.engine.cylinders)
# array([ 8, 24])
的np.dtype
功能并非绝对必要在这里,但它通常是好主意,并且每次让array
都会调用它,这会带来很小的速度提升。
请注意,rec.array
只在这里使用.engine
表示法。如果您使用了简单的np.array
,那么您会使用cars['engine']['cylinders']
是否https://stackoverflow.com/questions/19201868/how-to-set-dtype-for-nested-numpy-ndarray回答你的问题? – Eric