为什么这不打印出X,Y np数组

时间:2017-06-01 04:47:06

标签: python numpy

所以我有一个带有X,Y属性数字的数据帧activities_and_attractions。我想创建一个numpy数组

[[X1,Y1]

[X2,Y2]

[X3,Y3]]

但事实证明它只打印最后一行

data = np.array([activities_and_attractions.X[0], activities_and_attractions.Y[0]])

for i in range(len(activities_and_attractions.index)):
    np.vstack((data, np.array([activities_and_attractions.X[i], activities_and_attractions.Y[i]])))

print(data)

1 个答案:

答案 0 :(得分:1)

您需要在循环中将vstack的输出分配给data

for i in range(len(activities_and_attractions.index)):
    data = np.vstack((data, np.array([activities_and_attractions.X[i], activities_and_attractions.Y[i]])))  # assign to data

考虑使用numpy.append执行此任务。以这种方式发展ndarray效率不高。

出了什么问题:

data = np.array( (activities_and_attractions.X, activities_and_attractions.Y) )