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 0 1 0 0 0 1 1 0 1 1 0 1 0 0 0 0 
     0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 
     0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
     0 0 0 0 0 0"]) 
array(["0 0 0 1 1 0 0 0 0 0 0 1 0 1 0 0 0 1 0 1 0 0 0 
     0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 0 1 0 0 0 
     1 0 0 0 1 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 
     0 0 1 0 1 0 1 1 0 1 1 1 1 0 1 1 1 0 1 1 0 1 1 
     0 0 1 1 1 0 0 1 1 1 1 0 0 1 0 1 1 1 0 1 1 1 0 
     0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1 
     0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 0 1 0 0 
     0 1 1 0 0 1 0 1 1 1 0 0 0 0 1 0 1 0 0 0 0 0 0 
     0 1 0 1 1 1 1 0 1 0 0 0 1 1 0 1 1 0 1 0 0 0 0 
     0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 
     0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 
     0 0 0 0 0 0"])] 

這裏是我想要的代碼:

mapped = map(lambda x: str(x), oneHotEncodedX) 
list(mapped) 

但這插入新行字符和引號用[]括:

['[0 0 0 0 0 0 1 1 1 0 0 0 0 1 0 0 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0\n 1 1 1 1 0 1 1 0 0 1 0 1 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 1\n 0 1 1 0 0 1 0 1 0 1 1 1 0 1 0 1 0 0 0 0 1 1 1 1 1 1 1 1 1 0 1 1 0 1 1 1 0\n 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n 0 0 0 1 0 1 1 1 0 0 1 1 0 1 1 0 1 1 1 0 1 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0\n 1 0 1 1 1 1 0 1 0 0 0 1 1 0 1 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0\n 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]', 
'[0 0 0 1 1 0 0 0 0 0 0 1 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0\n 1 0 1 0 0 1 0 0 0 1 0 0 0 1 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 1\n 0 1 1 0 1 1 1 1 0 1 1 1 0 1 1 0 1 1 0 0 1 1 1 0 0 1 1 1 1 0 0 1 0 1 1 1 0\n 1 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0\n 0 0 0 1 0 1 0 1 0 0 1 0 0 0 1 1 0 0 1 0 1 1 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0\n 1 0 1 1 1 1 0 1 0 0 0 1 1 0 1 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0\n 0 0 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]'] 

如何轉換爲字符串數組,其中每個字符串所在的每個字符串包含子數組元素?

+1

你處理numpy的陣列?在這種情況下添加適當的標籤是值得的 – RomanPerekhrest

+0

使用此作爲參考a = [0,1,1,2,2,3]比print([「」.join(map(str,a))])) – Vaibhav

回答

2

我相信你可以使用:

out = list(map(lambda x: np.array(' '.join(x.astype(str))), oneHotEncodedX)) 

print(out) 
[array('0 0 0 0 0 0 1 1 1 0 0 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