0

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
1

1 Answer 1

2

This I believe is your answer. I don't know how to mark as a duplicate.

How to define two-dimensional array in python

answered Dec 10, 2015 at 12:38
Sign up to request clarification or add additional context in comments.

2 Comments

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.
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]];

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.