Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #109658 > unrolled thread
| Started by | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| First post | 2016-06-08 03:07 -0400 |
| Last post | 2016-06-08 01:13 -0700 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Possible PEP - two dimensional arrays? Terry Reedy <tjreedy@udel.edu> - 2016-06-08 03:07 -0400
Re: Possible PEP - two dimensional arrays? wxjmfauth@gmail.com - 2016-06-08 01:13 -0700
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2016-06-08 03:07 -0400 |
| Subject | Re: Possible PEP - two dimensional arrays? |
| Message-ID | <mailman.69.1465369688.2306.python-list@python.org> |
On 6/7/2016 8:17 PM, Harrison Chudleigh wrote: > I was programming a computer game and found that while 1D arrays can be > created using the module array, there is no module for two-dimensional > arrays, unlike languages like C. Currently, the closest thing Python has to > a 2D array is a dictionary containing lists. A list of lists is standard if one is not using numpy, indexed as, for instance 'board[i][j]' A tuple of tuples can be used for static 2d array. I expect people have also used a list of arrays, though for most games, the space saving is not enough, plus a list of list is more flexible, in that one can put a 'piece' on and 'square'. > I propose that a module , 2DArray, be added to the standard library. This > module will include: > Assignment and retrieval on items on a two-dimensional, finite rectangular > grid. Types are integer, float, character and string. > Resizing the grid - parameters are old size and new size. Any new elements > are initialized with a value of 0 for int, 0.0 for float and ' ' for string > and character arrays. > Removing elements. The parameter is the location. After removal, the value > returned is 0 for int, 0.0 for float and ' ' for string and character > arrays. > A function, pop(), which removes elements from the grid and then returns > them. You could create your own class based on a list of arrays, and even publish it. -- Terry Jan Reedy
[toc] | [next] | [standalone]
| From | wxjmfauth@gmail.com |
|---|---|
| Date | 2016-06-08 01:13 -0700 |
| Message-ID | <91fcebe4-2153-4ffa-8056-76180ed3ca43@googlegroups.com> |
| In reply to | #109658 |
Lists (list of lists) in action. >>> sys.version '3.2.5 (default, May 15 2013, 23:06:03) [MSC v.1500 32 bit (Intel)]' >>> >>> zz = vecmat.NewMat(3, 2) >>> zz[0][0] = 1.0; zz[0][1] = 2.0 >>> zz[1][0] = 3.0; zz[1][1] = 4.0 >>> zz[2][0] = 5.0; zz[2][1] = 5.0 >>> zz [[1.0, 2.0], [3.0, 4.0], [5.0, 5.0]] >>> vmio.pr(zz, 'zz=') zz= ( 1.00000e+000 2.00000e+000 ) ( 3.00000e+000 4.00000e+000 ) ( 5.00000e+000 5.00000e+000 ) >>> aa, b, cc = svdecomp.SVDecomp(zz) >>> bb = vecmat.VecToDiagMat(b) >>> cct = vecmat.TransposeMat(cc) >>> vmio.pr(aa, 'aa=') aa= ( 6.91451e-001 -2.42761e-001 ) ( 4.73049e-001 -5.59698e-001 ) ( -5.46004e-001 -7.92342e-001 ) >>> vmio.pr(bb, 'bb=') bb= ( 8.25102e-001 0.00000e+000 ) ( 0.00000e+000 8.90613e+000 ) >>> vmio.pr(cct, 'cct=') cct= ( -7.50721e-001 6.60619e-001 ) ( -6.60619e-001 -7.50721e-001 ) >>> rr = vecmat.MatMulMatMulMat(aa, bb, cct) >>> vmio.pr(rr, 'rr=') rr= ( 1.00000e+000 2.00000e+000 ) ( 3.00000e+000 4.00000e+000 ) ( 5.00000e+000 5.00000e+000 ) >>>
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web