thouis / numpy-trac-migration

numpy Trac to github issues migration
2 stars 3 forks source link

Assignment problem on matrix advanced selection (Trac #803) #4606

Open numpy-gitbot opened 12 years ago

numpy-gitbot commented 12 years ago

Original ticket http://projects.scipy.org/numpy/ticket/803 on 2008-05-31 by trac user jprey@noos.fr, assigned to unknown.

I found a problem when assigning a matrix to a matrix advanced selection in numpy 1.0.4.

m = numpy.matrix([[1, 2], [3, 4]])
m[[0, 0], [0, 1]] = numpy.matrix([-1, -2])

ValueError: array is not broadcastable to correct shape

This is specific to assigning a matrix to a matrix advanced selection. The following examples all work fine:

m = numpy.matrix([[1, 2], [3, 4]])
m[0] = numpy.matrix([-1, -2])

m = numpy.matrix([[1, 2], [3, 4]])
m[[0, 0], [0, 1]] = numpy.array([-1, -2])

Most surprisingly, the following example also works

m = numpy.matrix([[1, 2], [3, 4]])
m[numpy.matrix([0, 0]), numpy.matrix([0, 1])] = numpy.matrix([-1, -2])

I discovered this poblem while trying

m = numpy.matrix([[1, 2], [3, 4]])
m[m < 3] = -m[m < 3]

ValueError: array is not broadcastable to correct shape

I believe that if the integer advanced selection is fixed, the boolean advanced selection will also be corrected.

numpy-gitbot commented 12 years ago

atmention:mwiebe wrote on 2011-03-23

This is a matrix problem that's still there. A workaround is to do this:

In [47]: m = numpy.matrix([[1, 2], [3, 4]])

In [48]: m[[0, 0], [0, 1]] = numpy.array([-1, -2])
numpy-gitbot commented 12 years ago

Milestone changed to Unscheduled by atmention:mwiebe on 2011-03-23