Python Forum

Full Version: Save Numpy Array in Another Numpy Array (not Concatenate!)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello;
Here is my code
array1 = ([])
for triplet in itertools.product([0, 1], repeat=6):
    a,ap,b,bp,c,cp = triplet[0],triplet[1],triplet[2],triplet[3],triplet[4],triplet[5]
    nlist = [(a,b,c),(a,b,cp),(a,bp,c),(a,bp,cp),(ap,b,c),(ap,b,cp),(ap,bp,c),(ap,bp,cp)] 
    #arr2 = np.array([])
    arr = np.array([])
    for i in range(8):
        for l in range(8):
            if lst[l] == nlist[i]:
                arr = np.append(arr,[1])
                
            else:
                arr = np.append(arr,[0])
    array1=np.append(array1,arr) #Here is the problem. When I want to add my arr array to array1, the result is like concataneta 
    print(arr)
I want to add arr to array1 like that
array1([arr],[arr],[arr]….)
But the code is adding like that ([arr arr arr arr arr])
How can I solve the this problem?
Ok I solved my problem.

I changed my array type of array1 from numpy array to array like this link link
and It worked.