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