I have an double array
alist[1][1]=-1
alist2=[]
for x in xrange(10):
alist2.append(alist[x])
alist2[1][1]=15
print alist[1][1]
and I get 15. Clearly I’m passing a pointer rather than an actual variable… Is there an easy way to make a seperate double array (no shared pointers) without having to do a double for loop?
Thanks,
Dan
A list of lists is not usually a great solution for making a 2d array. You probably want to use numpy, which provides a very useful, efficient n-dimensional array type. numpy arrays can be copied.
Other solutions that are usually better than a plain list of lists include a dict with tuples as keys (
d[1, 1]would be the 1, 1 component) or defining your own 2d array class. Of course, dicts can be copied and you could abstract copying away for your class.To copy a list of lists, you can use
copy.deepcopy, which will go one level deep when copying.