【发布时间】:2014-02-25 02:09:59
【问题描述】:
我知道有很多关于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
【问题讨论】:
标签: arrays numpy jupyter-notebook