0

I need to get the following: ([[True, True, False, False, False, False],[ False, False,True, True, False, False],[False, False, False, False,True, True, ]])

I wrote the following:

def create_bool():
    x_bool =[True, True, False, False,
                     False, False]
    arr_bool = []
    for i in range(3):
        arr_bool.append(x_bool)
        print(arr_bool)
        x_bool[:] = x_bool[-2:] + x_bool[0:-2]
        i+=1
    return arr_bool

but I got:([[True, True, False, False, False, False], [True, True, False, False, False, False], [True, True, False, False, False, False]])

3
  • Your rotation is off slightly: x_bool = x_bool[-2:] + x_bool[:-2] Commented Nov 30, 2020 at 15:38
  • Why not just arr_bool = [[True, True, False, False, False, False],[ False, False,True, True, False, False],[False, False, False, False,True, True, ]]? Commented Nov 30, 2020 at 15:38
  • This is a simple example (real case may contain up to 10000 of True/ False) Commented Nov 30, 2020 at 16:35

1 Answer 1

1

you need to delete the index of x_bool set statement, and comment the i+=1. In a for loop the i automatically increases.

def create_bool():
    x_bool =[True, True, False, False, False, False]
    arr_bool = []
    for i in range(3):
        arr_bool.append(x_bool)
        x_bool = x_bool[-2:] + x_bool[0:-2]
        #i+=1
    
    print(arr_bool)
    
create_bool()

Output:

[[True, True, False, False, False, False], [False, False, True, True, False, False], [False, False, False, False, True, True]]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.