我知道有很多关于 中的列的问题被问到并得到了回答NumPy
,但我仍然被困住了。不幸的是,np.append
它对我不起作用,因为它说没有模块。
我正在使用数据集,该boston
数据集的中值与主数据分开存储boston.data
(形状为 (506, 13) 为boston.target
(形状为 (506, 1))。我想让它成为boston.target
特征(又名列)被添加到boston.data
,使其形状为 (506, 14),其中boston.data
[13] 为boston.target
数据。
根据我看到的其他建议,我的尝试是:
np.append(boston.data, boston.target, axis=0)
print boston.data.shape
但是,这给了我一个错误:
ValueError: all the input arrays must have same number of dimensions
这样做只是np.append(boston.data, boston.target)
没有给我任何回报boston.data
,或者至少据我所知。
我究竟做错了什么?
编辑:
如果有人ipython
打开,整个代码如下:
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from sklearn.datasets import load_boston
boston = load_boston()
print boston.data.shape
print boston.target.shape
copyarr = np.append(boston.data, boston.target, axis=1) #changed still runs error
print copyarr.shape
at --> copyarr = np.append(boston.data, boston.target, axis=1)
ValueError: all the input arrays must have the same number of dimensions