Talk:Creating an Array: Difference between revisions

 
(5 intermediate revisions by 5 users not shown)
Line 17:
 
:x86 assembly doesn't inherently support an array construct, unless one considers SIMD instructions to be indicative of such. However, in most of those cases, one is not dealing with multiple values in one variable, but with multiple variables. (Each register representing one variable.) I suppose one could consider register sets specific to SIMD extensions to be implied arrays.) --[[User:Short Circuit|Short Circuit]] 18:58, 22 January 2007 (EST)
 
:: I believe for most cpus "creating an array" could mean simply "allocating" memory for it (and "allocating" is rather vague or system specific, but reserving space on the user stack —if it exists, like in the x86 case— could be a possible meaning) --[[User:ShinTakezou|ShinTakezou]] 16:51, 9 April 2009 (UTC)
 
== I think the definition of array needs more elaboration before examples are shown. ==
Line 28 ⟶ 30:
::</quote>
:This is in fact wrong, 'echo $array[1][3] would print the 4th element within the second element, not the 3rd one. I'll edit tonight or something... --[[User:CrashandDie|CrashandDie]] 07:18, 2 July 2007 (EDT)
 
== Python ==
:''See also [[Two-dimensional array (runtime)]]''
Is there any easy way to do a Dim (like from Basic) on Python, as a multidimentional array?
'a=[0]*8' seems to be similar to 'dim a[8]', but i have no idea about how to do on an at least bidimentional array, since neither 'a=[0][0]*8' nor 'a=[0]*8[0]*8' works...
 
:Here are two ways to do two dim arrays in python:
 
>>> m,n = 3,4
>>> from pprint import pprint as pp
>>> a = dict(((x,y), 0) for x in range(m) for y in range(n))
>>> pp(a)
{(0, 0): 0,
(0, 1): 0,
(0, 2): 0,
(0, 3): 0,
(1, 0): 0,
(1, 1): 0,
(1, 2): 0,
(1, 3): 0,
(2, 0): 0,
(2, 1): 0,
(2, 2): 0,
(2, 3): 0}
>>> a[(0,0)] = 1
>>> a[(3,2)] = 1
>>> pp(a)
{(0, 0): 1,
(0, 1): 0,
(0, 2): 0,
(0, 3): 0,
(1, 0): 0,
(1, 1): 0,
(1, 2): 0,
(1, 3): 0,
(2, 0): 0,
(2, 1): 0,
(2, 2): 0,
(2, 3): 0,
(3, 2): 1}
>>> b = [[0]*m for _ in range(n)]
>>> pp(b)
[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]
>>> b[0][0] = 1
>>> b[3][2] = 1
>>> pp(b)
[[1, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 1]]
>>>
 
== Merge Create, Assign, and Retreive from Array ==
Line 35 ⟶ 85:
:Also, perhaps we could address the array definition issue mentioned above, as well, perhaps by specifying a "numerically-indexed array". --[[User:Short Circuit|Short Circuit]] 11:44, 20 October 2007 (MDT)
::Well, in my opinion if you stop indexing by cardinals, then it is no longer an array. :) Associative arrays are poorly named. --[[User:IanOsgood|IanOsgood]] 12:47, 20 October 2007 (MDT)
:::Perhaps a rebranding as "tuple" is in order? --[[User:Short Circuit|Short Circuit]] 13:37, 20 October 2007 (MDT)
:Be sure to remove languages from this task once they're adequately represented in the others. --[[User:Short Circuit|Short Circuit]] 02:16, 13 August 2009 (UTC)