In python, how do you create an array of unknown dimensional size? I want to cre
ID: 3871796 • Letter: I
Question
In python, how do you create an array of unknown dimensional size?
I want to create an array of unknown dimensional size based on a number I recieve. To elaborate, let's say n = 2, it will output a 3D array {true, true, true}. If n = 3, then its output will be a 4D array {true, true, true, true}. Whatever the n value is, the return value will be an array of n + 1 dimensional size. How would I do this? (the hint i'm given says I could also use recursion if I wanted)
The function I'm working on is a truth table generator. I'm given an expression ('a and b') which extracts the variables and returns a truth table as a multidimensional list. Since there are 2 variables, the return value will be a 3D list. {a value, b value, result value}
Return value for the table above would be {{1, 1, 1},{1, 0, 0}, {0, 1, 0},{0, 0, 0}}. The format is {a value, b value, result}.
However, my function is supposed to account for complex expressions as well. Like this ('a and (b |implies| c)'). Since there are 3 variables, my return value should be a 4D list. {{1,1,1,1},{1,1,0,0}, ... , {0,0,0,0}}.
a b a and b 1 1 1 1 0 0 0 1 0 0 0 0Explanation / Answer
Please refer to the following process. In line 3 we declare X as [[None] * columns for x in xrange(rows)] rows = 209 columns = 10 X = [[None] * columns for x in xrange(rows)] len(X) 420 len(X[0]) 10
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.