How to create an array from the list of arrays in python I was trying to write a python code that can set some neural network channels or neurons to zero at the inference; and I wrote the code below. The code generates 10 different arrays for different percentage of the channels or neurons that are set to zero. My challenge is how to combine these arrays into a single array or a list so that they can be individually accessed, but all I was getting was a list containing arrays with zero elements. Please help me.

import numpy as np
def three_steps(n):
    return step(n, steps=[1, 0.5, 0.25])

B = np.linspace(0.1, 1.0, 10)
print B   
B = np.array(three_steps(100))
print "A = ", A

for i, value in enumerate(B):
    A[i:int(value*100)] = 0
    print A
list = [np.append(A, i) for k in range(i + 1)]
print list
This post from stack overflow should give you what you want. The magic code boils down to the following.

flat_list = [item for sublist in l for item in sublist]


You can also loop through the list of lists and merge them.

lists = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

merged_list = []

for l in lists:
    merged_list += l

print(merged_list)
[1, 2, 3, 4, 5, 6, 7, 8, 9]