1
我有以下为什么numpy形状是空的?
(Pdb) training
array(<418326x223957 sparse matrix of type '<type 'numpy.float64'>'
with 165657096 stored elements in Compressed Sparse Row format>, dtype=object)
(Pdb) training.shape
()
为什么没有形状信息?
编辑:这是我做了什么:
training, target, test, projectids = generate_features(outcomes, projects, resources)
target = np.array([1. if i == 't' else 0. for i in target])
projectids = np.array([i for i in projectids])
print 'vectorizing training features'
d = DictVectorizer(sparse=True)
training = d.fit_transform(training[:10].T.to_dict().values())
#test_data = d.fit_transform(training.T.to_dict().values())
test_data = d.transform(test[:10].T.to_dict().values())
print 'training shape: %s, %s' %(training.shape[0], training[1])
print 'test shape: %s, %s' %(test_data.shape[0], test_data[1])
print 'saving vectorized instances'
with open(filename, "wb") as f:
np.save(f, training)
np.save(f, test_data)
np.save(f, target)
np.save(f, projectids)
在这个时间点,我的训练的外形仍然(10, 121)
。
后来,我只是
with open("../data/f1/training.dat", "rb") as f:
training = np.load(f)
test_data = np.load(f)
target = np.load(f)
projectids = np.load(f)
重新初始化4个变量,但形状不见了。
你必须提供更多的上下文。没有足够的信息来推断发生了什么。至少,显示您编写的用于初始化分类器和训练数据的代码。 – lightalchemist
稀疏矩阵不是NumPy数组。他们甚至不认为arraylikes;大多数NumPy例程不知道如何处理一个例程。看看http://stackoverflow.com/questions/8955448/save-load-scipy-sparse-csr-matrix-in-portable-data-format – user2357112
它可能是有用的在这种情况下,'numpy'确实已知如何处理稀疏矩阵 - 将其包装在对象数组中。如果这有所作为,我使用numpy 1.9dev。 – hpaulj