I'm trying to create a 2-dimensional matrix with an array, but I don't quit understand it yet.
I've tried this:
for i in range(x):
for k in range(y):
array.array('u', [i] : [k])
I'm trying to make an field with x, y as in height and width.
edit:
well, I've changed it now and came to this solution, which fixes my problem
import array
x = int(input('width: '))
y = int(input('height: '))
Matrix = array.array("u", ['.' for i in range(x) for k in range(y)])
Matrix.tounicode
print(Matrix)
With this I'm creating a field as an array, although I have to see how tounicode really works, possible I need a hash-function.
Jason Aller
3,66028 gold badges43 silver badges40 bronze badges
asked Dec 10, 2015 at 12:32
PythonUserNew
911 silver badge5 bronze badges
-
Possible duplicate of How to define two-dimensional array in pythongabra– gabra2015年12月10日 13:16:48 +00:00Commented Dec 10, 2015 at 13:16
1 Answer 1
This I believe is your answer. I don't know how to mark as a duplicate.
answered Dec 10, 2015 at 12:38
Tomaltach
9232 gold badges11 silver badges31 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
PythonUserNew
But is it an array, or arraylist? Because i want it to have constant runtime. Thats what i dont quit get it yet, it seems i always get arraylist, and not an array.
Tomaltach
In the case I have linked to it would more resemble a dictionary in the likes of java. But you can look at it as a case of an array inside of an array. e.g. var array = [[0,0], [0,1]];
lang-py