Why isn't it appending all the lists?
test = {'file1':{'subfile1':[1,2,3],'subfile2':[10,11,12]},'file5':{'subfile1':[4,678,6]},'file2':{'subfile1':[4,78,6]},'file3':{'subfile1':[7,8,9]}}
testarray = np.array([50,60,70])
for file in test.keys():print(test[file]['subfile1'])subfile1 = np.append(testarray, test[file]['subfile1'])
print(subfile1)
numpy.append
returns a new NumPy array, while your code shows that you think it's adding new values to testarray
. The array is not appended in-place, a new array has to be created and filled with data, thus copying both testarray
and test[file]['subfile1']
.
Also, note that there's no need to loop over keys and extract a value from the dictionary by one of these keys. You can loop over the items the array contains, including both keys and values:
for key, value in test.items():print(value['subfile1'])...