Hi, I have a problem with fancy assignment. Even though left and right side of the assignment have the same shape, an exception occurs. numpy is freshly built 10 minutes ago. Minimal example: #################################################### import numpy print numpy.__version__ # --> 1.0.1.dev3462 array=numpy.array m = \ array([[[111, 112, 113, 114, 115, 116], [121, 122, 123, 124, 125, 126], [131, 132, 133, 134, 135, 136], [141, 142, 143, 144, 145, 146], [151, 152, 153, 154, 155, 156], [161, 162, 163, 164, 165, 166]], [[211, 212, 213, 214, 215, 216], [221, 222, 223, 224, 225, 226], [231, 232, 233, 234, 235, 236], [241, 242, 243, 244, 245, 246], [251, 252, 253, 254, 255, 256], [261, 262, 263, 264, 265, 266]]]) f = \ array([[[10111, 10112], [10121, 10122], [10131, 10132], [10141, 10142], [10151, 10152], [10161, 10162]], [[10211, 10212], [10221, 10222], [10231, 10232], [10241, 10242], [10251, 10252], [10261, 10262]]]) print m[:,:,(2,4)].shape # --> (2,6,2) print f.shape # --> (2,6,2) m[:,:,(2,4)] = f ################################################## # error message: --------------------------------------------------------------------------- exceptions.ValueError Traceback (most recent call last) /home/jloehnert/<console> ValueError: array is not broadcastable to correct shape #################################################### With a 2D array this kind of operation works fine. Is this a bug? Johannes
Johannes Loehnert wrote:
Hi,
I have a problem with fancy assignment. Even though left and right side of the assignment have the same shape, an exception occurs. numpy is freshly built 10 minutes ago.
This is a bug in NumPy. I've tracked it down and am trying to come up with a fix. Basically, I need to figure out the transpose tuple to use to invert a permutation that I'm using. If I do. b = a.transpose(perm) c = b.transpose(what) so that c and a have the same shape. I have a general formula for perm but I'm not quite sure how to translate that into a general formula for what. I may have to just calculate the inverse permutation in the code. -Travis.
participants (2)
-
Johannes Loehnert
-
Travis Oliphant