0
我在格式的某些數據(從CSV文件中取出):Python的劈裂萃取CSV數據
MyValues = [[2 2 2 1 1]
[2 2 2 2 1]
[1 2 2 1 1]
[2 1 2 1 2]
[2 1 2 1 2]
[2 1 2 1 2]
[2 1 2 1 2]
[2 2 2 1 1]
[1 2 2 1 1]]
我想這個數據拆分成2/3和1/3,並且能夠區分它們之間。例如
twoThirds = [[2 2 2 1 1]
[2 2 2 2 1]
[1 2 2 1 1]
[2 1 2 1 2]
[2 1 2 1 2]
[2 1 2 1 2]]
oneThird = [[2 1 2 1 2]
[2 2 2 1 1]
[1 2 2 1 1]]
我試圖使用下面的代碼來實現這一點,但我不確定是否我已經走過了這個正確的方式?
twoThirds = (MyValues * 2)/3 #What does this code provide me?
我不確定你在問什麼。它看起來像你試圖切片陣列。 twoThirds,oneThird = MyValues [:len(MyValues)* 2/3],MyValues [len(MyValues)* 2/3:]。 – 2013-02-12 20:01:56