The following function creates a 3 bit adder truth table with Sum and Carrier. Now, I want to use the output of the following function as an array for further operation.
import numpy as np
def truthTable(inputs=3):
if inputs == 3:
print(" A B C S Cout ")
for a in range(0, 2):
for b in range(0, 2):
for c in range(0, 2):
cout = eval("((a & b) | (a & c) | (b & c))")
s = eval("(a ^ b ^ c)")
print([str(a) + ", " + str(b) + ", " + str(c) + ", " + str(s) + ", " + str(cout)])
truthTable()
By using "print(np.array([truthTable()]))" command, I didn't get expected array structure. I want it as,
[[0, 0, 0, 0, 0]
..............
[1, 1, 1, 1, 1]]
- How can I get that array structure from this situation?
- Also, how to get rid of '' from the array, when this code execute? (e.g.['1, 1, 1, 1, 1'])
Thank you!