stephenrawls opened a new issue #13998: expand_dims() makes copy instead of simply reshaping URL: https://github.com/apache/incubator-mxnet/issues/13998 Hi, Not sure if this is expected behavior or a bug, but I noticed somewhat surprisingly that all `expand_dims()` calls in some code we were writing were making full copies of the underlying array we were expanding. In our case, the only reason to expand was to be able to broadcast arithmetic operations correctly, and it is unacceptable to make a copy. Our current work around is to use reshape directly. See example code which shows my point: ``` import mxnet as mx a = mx.nd.array([0]) reshaped = a.reshape(1,1) reshaped[0,0] = 5 print(a) # prints 5, because reshaped is a wrapper over a expanded = a.expand_dims(1) expanded[0,0] = 10 print(a) # prints 5, because expanded is a *copy* of a ``` I personally feel like expand_dims() should have the same behavior as reshape() here, but just be a more fluent way of reshaping an array in a particular way. Therefore I feel like it's a bug for it to make a copy. However I don't have the full context, and maybe there's a reason expand_dims needs to make a copy? Please let me know--and if not I can look into making a PR to get rid of spurious copy. Thanks, Stephen
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
