On Tue, Feb 23, 2016 at 8:45 AM, Benjamin Root <ben.v.r...@gmail.com> 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?
Sure, it's totally ambiguous. These are all legal: In [1]: a = np.zeros((0, 5, 64)) In [2]: a.shape = (0, 5 * 64) In [3]: a.shape = (0, 5 * 65) In [4]: a.shape = (0, 5, 102) In [5]: a.shape = (0, 102, 64) Generally, the -1 gets replaced by prod(old_shape) // prod(specified_entries_in_new_shape). If the specified new shape has a 0 in it, then this is a divide-by-zero. In this case it happens because it's the solution to the equation prod((0, 5, 64)) == prod((0, 5, x)) for which there is no unique solution for 'x'. Your proposed solution feels very heuristic-y to me, and heuristics make me very nervous :-/ If what you really want to say is "flatten axes 1 and 2 together", then maybe there should be some API that lets you directly specify *that*? As a bonus you might be able to avoid awkward tuple manipulations to compute the new shape. -n -- Nathaniel J. Smith -- https://vorpus.org _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org https://mail.scipy.org/mailman/listinfo/numpy-discussion