numpy array question

jagmit sandhu jagmit.sandhu at gmail.com
Wed Apr 1 21:40:33 EDT 2020


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


More information about the Python-list mailing list