How to pass from a binary char array to int array in python? [duplicate]
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]]
?
python arrays
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.
add a comment |
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]]
?
python arrays
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
add a comment |
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]]
?
python arrays
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
python arrays
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
add a comment |
[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
add a comment |
1 Answer
1
active
oldest
votes
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.
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
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
[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