# [Numpy-discussion] array allocation using tuples gives views of same array

Matthieu Brucher matthieu.brucher at gmail.com
Thu Nov 15 10:23:27 EST 2007

```It's not a question of tuple, you made a tuple, but in each element, you put
the same array, so this behaviour is to be expected.

Matthieu

2007/11/15, George Nurser <gnurser at googlemail.com>:
>
> I tried the (as I thought) nice compact form
> In : a,b = (zeros((2,)),)*2
>
> But...
>
> In : b = 2
>
> In : a
> Out: array([ 2.,  0.])
>
> a and b are the _same_ array....
>
> But
> In : a,b = (zeros((2,)),zeros((2,)))
>
> In : b = 2
>
> In : a
> Out: array([ 0.,  0.])
>
> is OK. a & b are independent in this case.
>
> I'm puzzled by this behaviour, I suspect because of my ignorance of
> how tuples work.
>
> It looks to me like
> a,b = (zeros((2,)),)*2
> is equivalent to
> x= zeros((2,))
> a,b=(x,)*2
>
> If this is indeed a feature rather than a bug, is there an alternative
> compact way to allocate many arrays?
>
>
> Regards, George.
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>

--
French PhD student
Website : http://miles.developpez.com/
Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92