ValueError: all the input arrays must have same number of dimensions

后端 未结 4 949
既然无缘
既然无缘 2020-12-24 03:28

I\'m having a problem with np.append.

I\'m trying to duplicate the last column of 20x361 matrix n_list_converted by using the code below:

4条回答
  •  情深已故
    2020-12-24 04:07

    You can also cast (n,) to (n,1) by enclosing within brackets [ ].

    e.g. Instead of np.append(b,a,axis=0) use np.append(b,[a],axis=0)

    a=[1,2]
    b=[[5,6],[7,8]]
    np.append(b,[a],axis=0)
    

    returns

    array([[5, 6],
           [7, 8],
           [1, 2]])
    

提交回复
热议问题