Il giorno giovedì 2 aprile 2020 06:30:22 UTC+2, jagmit sandhu ha scritto: > python newbie. I can't understand the following about numpy arrays: > > x = np.array([[0, 1],[2,3],[4,5],[6,7]]) > x > array([[0, 1], > [2, 3], > [4, 5], > [6, 7]]) > x.shape > (4, 2) > y = x[:,0] > y > array([0, 2, 4, 6]) > y.shape > (4,) > > Why is the shape for y reported as (4,) ? I expected it to be a (4,1) array. > thanks in advance
Because is not Matlab where everything is at least a 2d array. If you fix a dimension that dimension disappear. It is the same behaviour as that of Fortran. Personally I think that the Python behaviour is more natural and obvious. As always it is a choice of who has written the library what will happen with a slice. -- https://mail.python.org/mailman/listinfo/python-list