0

i'm trying to create an 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, wich fixs 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 an field as an array, although i have to see how tounicode really works, possible i need a hash-function.

PythonUserNew
  • 91
  • 1
  • 5
  • Possible duplicate of [How to define two-dimensional array in python](http://stackoverflow.com/questions/6667201/how-to-define-two-dimensional-array-in-python) – gabra Dec 10 '15 at 13:16

1 Answers1

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

Community
  • 1
  • 1
Tomaltach
  • 913
  • 1
  • 11
  • 30
  • 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. – PythonUserNew Dec 10 '15 at 12:43
  • 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]]; – Tomaltach Dec 10 '15 at 12:46