2014-07-04 41 views
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個變量,但形狀不見了。

+0

你必須提供更多的上下文。沒有足夠的信息來推斷髮生了什麼。至少,顯示您編寫的用於初始化分類器和訓練數據的代碼。 – lightalchemist

+0

稀疏矩陣不是NumPy數組。他們甚至不認爲arraylikes;大多數NumPy例程不知道如何處理一個例程。看看http://stackoverflow.com/questions/8955448/save-load-scipy-sparse-csr-matrix-in-portable-data-format – user2357112

+0

它可能是有用的在這種情況下,'numpy'確實已知如何處理稀疏矩陣 - 將其包裝在對象數組中。如果這有所作爲,我使用numpy 1.9dev。 – hpaulj

回答

4

有一個在

array(<418326x223957 sparse matrix of type '<type 'numpy.float64'>' 
    with 165657096 stored elements in Compressed Sparse Row format>, dtype=object) 

形狀信息這是一個項目,並且0的尺寸,因此,形狀()的陣列。那一項是dtype=object。具體來說,它是一個稀疏陣列 - 尺寸顯示在屏幕<418...x22...中。

我打算詢問DictVectorizerfit_transform,但那並不重要。這是保存和加載操作來更改值。

我的猜測是你沒有加載你剛剛寫的文件。


np.save(f,training)與D型object包裹在np.array稀疏矩陣。這就是你看到的負載。

training = training.item() 

將稀疏矩陣從數組包裝器中取出。

418326x223957training的形狀與完整的數據集,和(10, 121)減少調試集的形狀?