From: Keith G. <kwg...@gm...> - 2006-06-27 16:45:59
|
This works in numpy 0.9.7.2416 but doesn't work in numpy 0.9.9.2683: Numpy 0.9.9.2683 x = asmatrix(zeros((3,2), float)) y = asmatrix(rand(3,1)) y matrix([[ 0.49865026], [ 0.82675808], [ 0.30285247]]) x[:,1] = y > 0.5 x matrix([[ 0., 0.], [ 0., 0.], <--- this should be one (?) [ 0., 0.]]) But it worked in 0.9.7.2416: x = asmatrix(zeros((3,2), float)) y = asmatrix(rand(3,1)) y matrix([[ 0.35444501], [ 0.7032141 ], [ 0.0918561 ]]) x[:,1] = y > 0.5 x matrix([[ 0., 0.], [ 0., 1.], [ 0., 0.]]) |
From: Stefan v. d. W. <st...@su...> - 2006-06-27 18:13:16
|
On Tue, Jun 27, 2006 at 09:45:57AM -0700, Keith Goodman wrote: > This works in numpy 0.9.7.2416 but doesn't work in numpy 0.9.9.2683: >=20 > Numpy 0.9.9.2683 >=20 > x =3D asmatrix(zeros((3,2), float)) > y =3D asmatrix(rand(3,1)) > y >=20 > matrix([[ 0.49865026], > [ 0.82675808], > [ 0.30285247]]) >=20 > x[:,1] =3D y > 0.5 > x >=20 > matrix([[ 0., 0.], > [ 0., 0.], <--- this should be one (?) > [ 0., 0.]]) With r2691 I see In [7]: x =3D N.asmatrix(N.zeros((3,2)),float) In [8]: y =3D N.asmatrix(N.rand(3,1)) In [12]: x[:,1] =3D y > 0.5 In [13]: x Out[13]: matrix([[ 0., 1.], [ 0., 1.], [ 0., 1.]]) Cheers St=E9fan |
From: Travis O. <oli...@ie...> - 2006-06-27 18:50:07
|
Stefan van der Walt wrote: > On Tue, Jun 27, 2006 at 09:45:57AM -0700, Keith Goodman wrote: > > With r2691 I see > > In [7]: x = N.asmatrix(N.zeros((3,2)),float) > > In [8]: y = N.asmatrix(N.rand(3,1)) > > In [12]: x[:,1] = y > 0.5 > > In [13]: x > Out[13]: > matrix([[ 0., 1.], > [ 0., 1.], > [ 0., 1.]]) > This was a bug, indirectly caused by the move to broadcasted copying and casting and the use of a matrix here. Previously the shapes didn't matter as long as the total size was the same. Thus internally x[:,1] was creating a (1,3) matrix referencing the last column of x (call it xp) and y>0.5 was a (3,1) matrix (call it yp) Thus the resulting casting code was repeatedly filling in x with (y>0.5). Thus, the last entry of (y>0.5) was the one that resulted. Previously, this would have worked because the shape of the arrays didn't matter, but now they do. The real culprit was not allowing the matrices "getitem" method to be called (which would have correctly obtained a (3,1) matrix from x[:,1] and thus avoided the strange result. Thus, in SVN, now PyObject_GetItem is used instead of the default ndarray getitem. The upshot, is that this should now work --- and there is now a unit-test to check for it. Thanks to Keith for exposing this bug. -Travis |
From: Travis O. <oli...@ie...> - 2006-06-27 18:20:04
|
Keith Goodman wrote: > This works in numpy 0.9.7.2416 but doesn't work in numpy 0.9.9.2683: > > Numpy 0.9.9.2683 > > x = asmatrix(zeros((3,2), float)) > y = asmatrix(rand(3,1)) > y > > matrix([[ 0.49865026], > [ 0.82675808], > [ 0.30285247]]) > > x[:,1] = y > 0.5 > x > > matrix([[ 0., 0.], > [ 0., 0.], <--- this should be one (?) > [ 0., 0.]]) > > This looks like a bug, probably introduced recently during the re-write of the copying and casting code. Try checking out the revisions r2662 and r2660 to see which one works for you. I'll look into this problem. -Travis |
From: Keith G. <kwg...@gm...> - 2006-06-27 18:44:11
|
On 6/27/06, Travis Oliphant <oli...@ie...> wrote: > Keith Goodman wrote: > > This works in numpy 0.9.7.2416 but doesn't work in numpy 0.9.9.2683: > > > > Numpy 0.9.9.2683 > > > > x = asmatrix(zeros((3,2), float)) > > y = asmatrix(rand(3,1)) > > y > > > > matrix([[ 0.49865026], > > [ 0.82675808], > > [ 0.30285247]]) > > > > x[:,1] = y > 0.5 > > x > > > > matrix([[ 0., 0.], > > [ 0., 0.], <--- this should be one (?) > > [ 0., 0.]]) > > > > > > This looks like a bug, probably introduced recently during the re-write > of the copying and casting code. Try checking out the revisions r2662 > and r2660 to see which one works for you. I'll look into this problem. Thanks for the tip. I get some extra output with r2660. It prints out "Source array" and "Dest. array" like this: >> x = asmatrix(zeros((3,2), float)) >> x matrix([[ 0., 0.], [ 0., 0.], [ 0., 0.]]) >> y = asmatrix(rand(3,1)) >> y matrix([[ 0.60117193], [ 0.43883293], [ 0.01633154]]) >> x[:,1] = y > 0.5 Source array = (3 1) Dest. array = (1 3) >> x matrix([[ 0., 1.], [ 0., 0.], [ 0., 0.]]) |