| | |
Multi-dimensional Arrays:
![]() |
I have read that Python does not have built-in support for multi-dimensional arrays-- is this still the case or has this been developed and updated in the last few years for this language?
I have researched this and seen references to multi-dimensional arrays and various work-arounds: dictionaries, lists, and various packages such as NumPy. Honestly, I do not need anything very sophisticated at this point. I suppose dictionaries will work fine (I just need to experiment with it a bit before deciding).
Has anyone here made attempts at simulating a multi-dimensional array, and if so, how did it work out for you?
Thank-you in advance.
Matty D
I have researched this and seen references to multi-dimensional arrays and various work-arounds: dictionaries, lists, and various packages such as NumPy. Honestly, I do not need anything very sophisticated at this point. I suppose dictionaries will work fine (I just need to experiment with it a bit before deciding).
Has anyone here made attempts at simulating a multi-dimensional array, and if so, how did it work out for you?
Thank-you in advance.
Matty D
Last edited by mattyd; Feb 19th, 2007 at 2:42 pm. Reason: (sp)
Sure Python has multidimensional arrays, they are called lists of lists or tuples of tuples etc.
python Syntax (Toggle Plain Text)
mlist1 = [ [7, 12, 23], [22, 31, 9], [4, 17, 31]] print mlist1 # [[7, 12, 23], [22, 31, 9], [4, 17, 31]] # show list_item at index 1 print mlist1[1] # [22, 31, 9] # show item 2 in that sublist print mlist1[1][2] # 9 # change the value mlist1[1][2] = 99 print mlist1 # [[7, 12, 23], [22, 31, 99], [4, 17, 31]]
Last edited by bumsfeld; Feb 19th, 2007 at 3:10 pm. Reason: spells
•
•
•
•
Sure Python has multidimensional arrays, they are called lists of lists or tuples of tuples etc.
python Syntax (Toggle Plain Text)
mlist1 = [ [7, 12, 23], [22, 31, 9], [4, 17, 31]] print mlist1 # [[7, 12, 23], [22, 31, 9], [4, 17, 31]] # show list_item at index 1 print mlist1[1] # [22, 31, 9] # show item 2 in that sublist print mlist1[1][2] # 9 # change the value mlist1[1][2] = 99 print mlist1 # [[7, 12, 23], [22, 31, 99], [4, 17, 31]]

Matty D
I was just playing around with a matrix the other day and found out this:
python Syntax (Toggle Plain Text)
# create a 10 x 10 matrix of zeroes matrix10x10 = [[0 for col in range(10)] for row in range(10)] # fill it with 1 diagonally for i in range(10): matrix10x10[i][i] = 1 # show it for row in matrix10x10: print row """ [1, 0, 0, 0, 0, 0, 0, 0, 0, 0] [0, 1, 0, 0, 0, 0, 0, 0, 0, 0] [0, 0, 1, 0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 1, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 1, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 1, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 1, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 1, 0, 0] [0, 0, 0, 0, 0, 0, 0, 0, 1, 0] [0, 0, 0, 0, 0, 0, 0, 0, 0, 1] """
No one died when Clinton lied.
•
•
Join Date: Jul 2006
Posts: 608
Reputation:
Solved Threads: 150
The difficulty comes in trying to make your multi-d array into a class with useful methods like __add__(), __mul__(), det(), eigenvalues(), etc.
When I was much fresher at Python, I tried creating a vector class that inherited from the tuple class. The attempt failed, and I moved on to other projects.
Anyone have success in such matters?
Jeff
When I was much fresher at Python, I tried creating a vector class that inherited from the tuple class. The attempt failed, and I moved on to other projects.
Anyone have success in such matters?
Jeff
Last edited by jrcagle; Feb 22nd, 2007 at 11:22 pm.
![]() |
Similar Threads
- (reformatted) How to return Multi-Dimensional Arrays (C++)
- Addition with Two Dimensional Arrays (C++)
- Creating a multi-dimensional Session variable (PHP)
- What relation does **indirection operator have with Multidimensional Arrays (C++)
- How to implement multi-dimensional arrays in Python?? (Python)
- Arrays (PHP)
- Need help passing a multi-dimensional array (C++)
Other Threads in the Python Forum
- Previous Thread: old-style class
- Next Thread: Play Flash Files with wxPython
| Thread Tools | Search this Thread |
alarm ansi assignment avogadro backend beginner binary bluetooth character cmd code customdialog cx-freeze data decimals dictionary directory dynamic error examples exe file float format function generator gnu graphics gui halp heads homework http ideas import input itunes java leftmouse line linux list lists loop maze module mouse number numbers output parsing path pointer port prime programming progressbar projects push py2exe pygame pyglet pyqt python random recursion schedule screensaverloopinactive script scrolledtext slicenotation sqlite ssh statistics string strings sudokusolver sum terminal text thread threading time tlapse tricks tuple tutorial ubuntu unicode urllib urllib2 variable ventrilo vigenere web webservice wikipedia write wxpython xlib






