I'd be more than happy to write up the patch. I don't think it would be quite like make zeros be ones, but it would be along those lines. One case I need to wrap my head around is to make sure that a 0 would happen if the following was true:
>>> a = np.ones((0, 5*64)) >>> a.shape = (-1, 5, 64) EDIT: Just tried the above, and it works as expected (zero in the first dim)! Just tried out a couple of other combos: >>> a.shape = (-1,) >>> a.shape (0,) >>> a.shape = (-1, 5, 64) >>> a.shape (0, 5, 64) This is looking more and more like a bug to me. Ben Root On Tue, Feb 23, 2016 at 1:58 PM, Sebastian Berg <sebast...@sipsolutions.net> wrote: > On Di, 2016-02-23 at 11:45 -0500, Benjamin Root wrote: > > but, it isn't really ambiguous, is it? The -1 can only refer to a > > single dimension, and if you ignore the zeros in the original and new > > shape, the -1 is easily solvable, right? > > I think if there is a simple logic (like using 1 for all zeros in both > input and output shape for the -1 calculation), maybe we could do it. I > would like someone to think about it carefully that it would not also > allow some unexpected generalizations. And at least I am getting a > BrainOutOfResourcesError right now trying to figure that out :). > > - Sebastian > > > > Ben Root > > > > On Tue, Feb 23, 2016 at 11:41 AM, Warren Weckesser < > > warren.weckes...@gmail.com> wrote: > > > > > > > > > On Tue, Feb 23, 2016 at 11:32 AM, Benjamin Root < > > > ben.v.r...@gmail.com> wrote: > > > > Not exactly sure if this should be a bug or not. This came up in > > > > a fairly general function of mine to process satellite data. > > > > Unexpectedly, one of the satellite files had no scans in it, > > > > triggering an exception when I tried to reshape the data from it. > > > > > > > > >>> import numpy as np > > > > >>> a = np.zeros((0, 5*64)) > > > > >>> a.shape > > > > (0, 320) > > > > >>> a.shape = (0, 5, 64) > > > > >>> a.shape > > > > (0, 5, 64) > > > > >>> a.shape = (0, 5*64) > > > > >>> a.shape = (0, 5, -1) > > > > Traceback (most recent call last): > > > > File "<stdin>", line 1, in <module> > > > > ValueError: total size of new array must be unchanged > > > > > > > > So, if I know all of the dimensions, I can reshape just fine. But > > > > if I wanted to use the nifty -1 semantic, it completely falls > > > > apart. I can see arguments going either way for whether this is a > > > > bug or not. > > > > > > > > > > When you try `a.shape = (0, 5, -1)`, the size of the third > > > dimension is ambiguous. From the Zen of Python: "In the face of > > > ambiguity, refuse the temptation to guess." > > > > > > Warren > > > > > > > > > > > > > > > > > Thoughts? > > > > > > > > Ben Root > > > > > > > > _______________________________________________ > > > > NumPy-Discussion mailing list > > > > NumPy-Discussion@scipy.org > > > > https://mail.scipy.org/mailman/listinfo/numpy-discussion > > > > > > > > > > _______________________________________________ > > > NumPy-Discussion mailing list > > > NumPy-Discussion@scipy.org > > > https://mail.scipy.org/mailman/listinfo/numpy-discussion > > > > > _______________________________________________ > > NumPy-Discussion mailing list > > NumPy-Discussion@scipy.org > > https://mail.scipy.org/mailman/listinfo/numpy-discussion > > _______________________________________________ > NumPy-Discussion mailing list > NumPy-Discussion@scipy.org > https://mail.scipy.org/mailman/listinfo/numpy-discussion > >
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org https://mail.scipy.org/mailman/listinfo/numpy-discussion