Python Numpy:不推荐使用reshape

时间:2017-03-09 21:00:47

标签: python pandas numpy

我正在尝试将矢量重塑为数组

myArray = np.reshape(myVector,[nCol,nRow])

但我收到折旧警告:

FutureWarning: reshape is deprecated and will raise in a subsequent release. Please use .values.reshape(...) instead
  return reshape(newshape, order=order)

当我使用

myArray = np.values.reshape(myVector,[nCol,nRow])

我收到错误

AttributeError: module 'numpy' has no attribute 'values'

请有人解释发生了什么以及我应该做什么?非常感谢

2 个答案:

答案 0 :(得分:4)

调用np.reshape(无论args)不再是调用该函数的首选方法。相反,使用它:

    myArray = myVector.values.reshape([nCol,nRow])

答案 1 :(得分:0)

我用这个解决了我的问题:

train_set_X = train_df["STRAIGHT_DIST"]
train_set_X_np = np.array(train_set_X)
train_set_X_np = train_set_X_np.reshape([train_set_X.shape[0], 1]) 

在您的具体情况下,您应该使用:

myVector_np = np.array(myVector)
myVector_np = myVector_np.reshape([myVector.shape[0], 1])