python - Stacking arrays in numpy using vstack -


array1.shape gives (180, ) array2.shape gives (180, 1)

what's difference between these two? , because of difference i'm unable stack them using

np.vstack((array2, array1)) 

what changes should make array1 shape can stack them up?

let's define arrays:

>>> x = np.zeros((4, 1)) >>> y = np.zeros((4)) 

as is, these arrays fail stack:

>>> np.vstack((x, y)) traceback (most recent call last):   file "<stdin>", line 1, in <module>   file "/usr/lib/python3/dist-packages/numpy/core/shape_base.py", line 230, in vstack     return _nx.concatenate([atleast_2d(_m) _m in tup], 0) valueerror: input array dimensions except concatenation axis must match 

however, simple change, stack:

>>> np.vstack((x, y[:, none])) array([[ 0.],        [ 0.],        [ 0.],        [ 0.],        [ 0.],        [ 0.],        [ 0.],        [ 0.]]) 

alternatively:

>>> np.vstack((x[:, 0], y)) array([[ 0.,  0.,  0.,  0.],        [ 0.,  0.,  0.,  0.]]) 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -