2
我正在嘗試使用Python和NumPy解決問題的Kaggle Titanic tutorial。我很難理解數據[0 ::,]和數據[0 :,]之間的區別。我複製粘貼下面的相關代碼片段:0 ::和0之間有什麼區別:過濾一個numpy數組?
for i in xrange(number_of_classes): #loop through each class
for j in xrange(number_of_price_brackets): #loop through each price bin
women_only_stats = data[ # Which element
(data[0::, 4] == "female") & # is a female and
(data[0::, 2].astype(np.float) # was ith class
== i+1)
& # and
(data[0:, 9].astype(np.float) # was greater
>= j * fare_bracket_size) # than this bin
& # and
(data[0:, 9].astype(np.float) # less than
< (j+1)*fare_bracket_size) # the next bin
, 1] # in the 2nd col
我不希望那裏有*任何*區別,你是否嘗試切換,看看結果是否改變?兩者都在切片中使用默認的「stop」和「step」。 – jonrsharpe
@wim啊這是真的,教程是使用2.7。不過'numpy'實際上是這樣做的嗎? – jonrsharpe
不,我誤解了,因爲在OP的情況下它總是帶有一個元組getitem。 – wim