📚 The CoCalc Library - books, templates and other resources
License: OTHER
This is a final exercise to get you comfortable working with numpy arrays. In this exercise, we're going to be programmatically constructing truth tables from boolean vectors. A truth table lists all possible Boolean outputs for the given inputs. For example, an AND truth table would look like this:
0 | 0 | 0 |
---|---|---|
0 | 1 | 0 |
1 | 0 | 0 |
1 | 1 | 1 |
Each row corresponds to different values of (first column) and (second column), and the third column corresponds to whatever is.
We can represent the different values of and using boolean arrays in numpy:
You can compute the logical AND of a
and b
using the &
operator (and the symbols for the Boolean operations OR and NOT are |
and ~
, respectively).
Part A: AND Table (1.25 points)
After you have implemented and_table
above, you can try running it with inputs a
and b
:
Part B: OR Table (1.25 points)
After you have implemented or_table
above, you can try running it with inputs a
and b
:
Part C: NOT Table (1.25 points)
After you have implemented not_table
above, you can try running it with inputs a
and b
: