How to pass from a binary char array to int array in python? [duplicate]












-3
















This question already has an answer here:




  • Convert a binary to an array with each binary number

    2 answers




I have this array "m":



m = ['0000', '0001', '0010', '0011', '1111']


How could I use a lambda function to change its format to:



n1 = [0,0,0,0,0,0,0,1,0,0,1,0,0,0,1,1,1,1,1,1]


or to:



n2 = [[0,0,0,0],[0,0,0,1],[0,0,1,0],[0,0,1,1],[1,1,1,1]]


?










share|improve this question















marked as duplicate by Robert Harvey Nov 21 '18 at 22:03


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • [int(x) for x in '12345'] will get you the inner array.

    – Robert Harvey
    Nov 21 '18 at 22:02













  • You can create n2 with list comprehensions: n2 = [[int(char_i) for char_i in char] for char in m]

    – vinsce
    Nov 21 '18 at 22:09











  • n0 = [list(item) for item in m]; n1 = [int(i) for lst in n0 for i in lst]; n2 = [[int(i) for i in lst] for lst in n0]

    – berkelem
    Nov 21 '18 at 22:17
















-3
















This question already has an answer here:




  • Convert a binary to an array with each binary number

    2 answers




I have this array "m":



m = ['0000', '0001', '0010', '0011', '1111']


How could I use a lambda function to change its format to:



n1 = [0,0,0,0,0,0,0,1,0,0,1,0,0,0,1,1,1,1,1,1]


or to:



n2 = [[0,0,0,0],[0,0,0,1],[0,0,1,0],[0,0,1,1],[1,1,1,1]]


?










share|improve this question















marked as duplicate by Robert Harvey Nov 21 '18 at 22:03


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • [int(x) for x in '12345'] will get you the inner array.

    – Robert Harvey
    Nov 21 '18 at 22:02













  • You can create n2 with list comprehensions: n2 = [[int(char_i) for char_i in char] for char in m]

    – vinsce
    Nov 21 '18 at 22:09











  • n0 = [list(item) for item in m]; n1 = [int(i) for lst in n0 for i in lst]; n2 = [[int(i) for i in lst] for lst in n0]

    – berkelem
    Nov 21 '18 at 22:17














-3












-3








-3









This question already has an answer here:




  • Convert a binary to an array with each binary number

    2 answers




I have this array "m":



m = ['0000', '0001', '0010', '0011', '1111']


How could I use a lambda function to change its format to:



n1 = [0,0,0,0,0,0,0,1,0,0,1,0,0,0,1,1,1,1,1,1]


or to:



n2 = [[0,0,0,0],[0,0,0,1],[0,0,1,0],[0,0,1,1],[1,1,1,1]]


?










share|improve this question

















This question already has an answer here:




  • Convert a binary to an array with each binary number

    2 answers




I have this array "m":



m = ['0000', '0001', '0010', '0011', '1111']


How could I use a lambda function to change its format to:



n1 = [0,0,0,0,0,0,0,1,0,0,1,0,0,0,1,1,1,1,1,1]


or to:



n2 = [[0,0,0,0],[0,0,0,1],[0,0,1,0],[0,0,1,1],[1,1,1,1]]


?





This question already has an answer here:




  • Convert a binary to an array with each binary number

    2 answers








python arrays






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 22:36









Dr. Greg

617




617










asked Nov 21 '18 at 21:56









Adath SkydersonAdath Skyderson

126




126




marked as duplicate by Robert Harvey Nov 21 '18 at 22:03


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Robert Harvey Nov 21 '18 at 22:03


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • [int(x) for x in '12345'] will get you the inner array.

    – Robert Harvey
    Nov 21 '18 at 22:02













  • You can create n2 with list comprehensions: n2 = [[int(char_i) for char_i in char] for char in m]

    – vinsce
    Nov 21 '18 at 22:09











  • n0 = [list(item) for item in m]; n1 = [int(i) for lst in n0 for i in lst]; n2 = [[int(i) for i in lst] for lst in n0]

    – berkelem
    Nov 21 '18 at 22:17



















  • [int(x) for x in '12345'] will get you the inner array.

    – Robert Harvey
    Nov 21 '18 at 22:02













  • You can create n2 with list comprehensions: n2 = [[int(char_i) for char_i in char] for char in m]

    – vinsce
    Nov 21 '18 at 22:09











  • n0 = [list(item) for item in m]; n1 = [int(i) for lst in n0 for i in lst]; n2 = [[int(i) for i in lst] for lst in n0]

    – berkelem
    Nov 21 '18 at 22:17

















[int(x) for x in '12345'] will get you the inner array.

– Robert Harvey
Nov 21 '18 at 22:02







[int(x) for x in '12345'] will get you the inner array.

– Robert Harvey
Nov 21 '18 at 22:02















You can create n2 with list comprehensions: n2 = [[int(char_i) for char_i in char] for char in m]

– vinsce
Nov 21 '18 at 22:09





You can create n2 with list comprehensions: n2 = [[int(char_i) for char_i in char] for char in m]

– vinsce
Nov 21 '18 at 22:09













n0 = [list(item) for item in m]; n1 = [int(i) for lst in n0 for i in lst]; n2 = [[int(i) for i in lst] for lst in n0]

– berkelem
Nov 21 '18 at 22:17





n0 = [list(item) for item in m]; n1 = [int(i) for lst in n0 for i in lst]; n2 = [[int(i) for i in lst] for lst in n0]

– berkelem
Nov 21 '18 at 22:17












1 Answer
1






active

oldest

votes


















0














m = ['0000', '0001', '0010', '0011', '1111']
funct = lambda m: [int(x) for x in ''.join(m)];


This will express list "m" as list "n1" with a lambda function as requested.






share|improve this answer


























  • Could I do it without loop? Maybe lambda function

    – Adath Skyderson
    Nov 21 '18 at 22:09











  • n1 = [int(x) for x in ''.join(m)]

    – Dr. Greg
    Nov 21 '18 at 22:12











  • funct = lambda m: [int(x) for x in ''.join(m)];

    – Dr. Greg
    Nov 21 '18 at 22:15


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














m = ['0000', '0001', '0010', '0011', '1111']
funct = lambda m: [int(x) for x in ''.join(m)];


This will express list "m" as list "n1" with a lambda function as requested.






share|improve this answer


























  • Could I do it without loop? Maybe lambda function

    – Adath Skyderson
    Nov 21 '18 at 22:09











  • n1 = [int(x) for x in ''.join(m)]

    – Dr. Greg
    Nov 21 '18 at 22:12











  • funct = lambda m: [int(x) for x in ''.join(m)];

    – Dr. Greg
    Nov 21 '18 at 22:15
















0














m = ['0000', '0001', '0010', '0011', '1111']
funct = lambda m: [int(x) for x in ''.join(m)];


This will express list "m" as list "n1" with a lambda function as requested.






share|improve this answer


























  • Could I do it without loop? Maybe lambda function

    – Adath Skyderson
    Nov 21 '18 at 22:09











  • n1 = [int(x) for x in ''.join(m)]

    – Dr. Greg
    Nov 21 '18 at 22:12











  • funct = lambda m: [int(x) for x in ''.join(m)];

    – Dr. Greg
    Nov 21 '18 at 22:15














0












0








0







m = ['0000', '0001', '0010', '0011', '1111']
funct = lambda m: [int(x) for x in ''.join(m)];


This will express list "m" as list "n1" with a lambda function as requested.






share|improve this answer















m = ['0000', '0001', '0010', '0011', '1111']
funct = lambda m: [int(x) for x in ''.join(m)];


This will express list "m" as list "n1" with a lambda function as requested.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 '18 at 22:28

























answered Nov 21 '18 at 22:02









Dr. GregDr. Greg

617




617













  • Could I do it without loop? Maybe lambda function

    – Adath Skyderson
    Nov 21 '18 at 22:09











  • n1 = [int(x) for x in ''.join(m)]

    – Dr. Greg
    Nov 21 '18 at 22:12











  • funct = lambda m: [int(x) for x in ''.join(m)];

    – Dr. Greg
    Nov 21 '18 at 22:15



















  • Could I do it without loop? Maybe lambda function

    – Adath Skyderson
    Nov 21 '18 at 22:09











  • n1 = [int(x) for x in ''.join(m)]

    – Dr. Greg
    Nov 21 '18 at 22:12











  • funct = lambda m: [int(x) for x in ''.join(m)];

    – Dr. Greg
    Nov 21 '18 at 22:15

















Could I do it without loop? Maybe lambda function

– Adath Skyderson
Nov 21 '18 at 22:09





Could I do it without loop? Maybe lambda function

– Adath Skyderson
Nov 21 '18 at 22:09













n1 = [int(x) for x in ''.join(m)]

– Dr. Greg
Nov 21 '18 at 22:12





n1 = [int(x) for x in ''.join(m)]

– Dr. Greg
Nov 21 '18 at 22:12













funct = lambda m: [int(x) for x in ''.join(m)];

– Dr. Greg
Nov 21 '18 at 22:15





funct = lambda m: [int(x) for x in ''.join(m)];

– Dr. Greg
Nov 21 '18 at 22:15





Popular posts from this blog

How to send String Array data to Server using php in android

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Is anime1.com a legal site for watching anime?