我尝试在一个数组中附加许多numpy数组:
path ='C:\\Users\\user\\Traces'
traces= os.listdir(path)
tempTracesHW[HW].append([np.load(os.path.join(path, trace)) for trace in traces])
此代码的结果是:
[[], [[array([[ 0.01437869, 0.01506449, 0.01579909, ..., 0.04166172,
0.0417285 , 0.04172079]], dtype=float32),..........., array([[ 0.00418158, 0.00483142, 0.00547356, ..., -0.0032004 ,
-0.00326461, -0.00333396]], dtype=float32), array([[-0.02872655, -0.02783527, -0.02693371, ..., 0.00331342,
0.00272522, 0.00211391]], dtype=float32)]], []]
但是,我需要的是这种结构:
[array([ 0.06542969, 0.03808594, 0.07910156, ..., 0.06542969,
0.07910156, 0.10449219]), array([ 0.0625 , 0.0390625 , 0.07421875, ..., 0.14355469,
0.04296875, 0.06640625])]
如何解决这个问题?
答案 0 :(得分:0)
numpy concatenate可能很有意思:
https://docs.scipy.org/doc/numpy/reference/generated/numpy.concatenate.html
即
tempTracesHW[HW] = np.concatenate([tempTracesHW[HW], np.concatenate( [np.load(os.path.join(path, trace)) for trace in traces]))
或者其他什么。