[Numpy-discussion] shape setting problem
Robert Cimrman
cimrman3 at ntc.zcu.cz
Wed Apr 12 05:59:28 EDT 2006
Hi,
I have found a wierd behaviour when setting a shape of a view of an
array, see below...
r.
---
In [43]:a = nm.zeros( (10,5) )
In [44]:b = a[:,2]
In [47]:b.fill( 3 )
In [48]:a
Out[48]:
array([[0, 0, 3, 0, 0],
[0, 0, 3, 0, 0],
[0, 0, 3, 0, 0],
[0, 0, 3, 0, 0],
[0, 0, 3, 0, 0],
[0, 0, 3, 0, 0],
[0, 0, 3, 0, 0],
[0, 0, 3, 0, 0],
[0, 0, 3, 0, 0],
[0, 0, 3, 0, 0]])
-------------------------------------------ok
In [49]:b.fill( 0 )
In [50]:a
Out[50]:
array([[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]])
In [51]:b.shape = (5,2)
In [52]:b
Out[52]:
array([[0, 0],
[0, 0],
[0, 0],
[0, 0],
[0, 0]])
In [53]:b.fill( 3 )
In [54]:a
Out[54]:
array([[0, 0, 3, 3, 3],
[3, 3, 3, 3, 3],
[3, 3, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]])
------------------------------------ wrong?
Should not this give the same result as Out[48]?
More information about the NumPy-Discussion
mailing list