pandas Python Numpy:不推荐使用 reshape
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42705313/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python Numpy: reshape is deprecated
提问by jlt199
I'm trying to reshape a vector into an array
我正在尝试将向量重塑为数组
myArray = np.reshape(myVector,[nCol,nRow])
but I get a depreciation warning:
但我收到折旧警告:
FutureWarning: reshape is deprecated and will raise in a subsequent release. Please use .values.reshape(...) instead
return reshape(newshape, order=order)
When I use
当我使用
myArray = np.values.reshape(myVector,[nCol,nRow])
I get an error
我收到一个错误
AttributeError: module 'numpy' has no attribute 'values'
Please can someone explain what's going on and what I should be doing? Many thanks
请有人解释发生了什么以及我应该做什么?非常感谢
回答by tbdees
calling np.reshape(whatever args) is no longer the preferred way to call the function. instead, use this: myArray = myVector.values.reshape([nCol,nRow])
调用 np.reshape(whatever args) 不再是调用函数的首选方式。相反,使用这个:myArray = myVector.values.reshape([nCol,nRow])
回答by u9377051
I have solved my problems using this:
我已经使用这个解决了我的问题:
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])
In your specific case, you should use this:
在您的特定情况下,您应该使用这个:
myVector_np = np.array(myVector)
myVector_np = myVector_np.reshape([myVector.shape[0], 1])