Benjamin Root
2016-02-23 16:32:12 UTC
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.
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.
Thoughts?
Ben Root
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 = np.zeros((0, 5*64))
a.shape
a.shape = (0, 5, 64)
a.shape
(0, 5, 64)a.shape
a.shape = (0, 5*64)
a.shape = (0, 5, -1)
Traceback (most recent call last):a.shape = (0, 5, -1)
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.
Thoughts?
Ben Root