python - Convert entries of an array to a list -


i have numpy arrays entries consists of either zeros or ones. example a = [ 0. 0. 0. 0.], b= [ 0. 0. 0. 1.], c= [ 0. 0. 1. 0.] want convert them list: l =['0000', '0001', '0010']. there easy way it?

you can convert each list string using join this

def join_list(x):     return ''.join([str(int(i)) in x])  = [0, 0, 0, 0] b = [0, 0, 0, 1] c = [0, 0, 1, 0]  print(join_list(a)) # 0000 

the can add them new list for loop

new_list = [] l in [a, b, c]:     new_list.append(join_list(l))  print(new_list) # ['0000', '0001', '0010'] 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -