Hi, I recently had troubles with the squeeze function from scipy_base. It squeezes all the dimensions when I pass a (1,1) array, resulting in an empty one! Is it a known side effect? Regards. JM. Philippe -------------------------- PS: I modified the 'site-packages/scipy_base/shape_base.py' script this way to get rid of the problem: def squeeze(a): "Returns a with any ones from the shape of a removed" a = asarray(a) b = asarray(a.shape) dims = tuple (compress (not_equal (b, 1), b)) if len(dims) == 0: dims = (1, ) val = reshape (a, dims) return val --------------------------
Jean-Michel Philippe wrote:
Hi,
I recently had troubles with the squeeze function from scipy_base. It squeezes all the dimensions when I pass a (1,1) array, resulting in an empty one!
I don't understand the problem. If you have a (1,1) array then according to the documentation squeeze should return an array with all dimensions of length one removed. Therefore, you end up with a zero-dimensional array (this is not an empty array...) It seems to work for me:
a = array([[5]]) a.shape (1, 1) b = squeeze(a) shape(b) () b 5
This is not a "side effect" but a documented effect. If you want to ensure a 1d array as it seems you do, then you could use b = atleast_1d(squeeze(a)) -Travis
participants (2)
-
Jean-Michel Philippe -
Travis E. Oliphant