我正在尝试使用Python和NumPy来解决解决问题的Kaggle Titanic tutorial。我很难理解data [0 ::,]和data [0:,]之间的区别。我复制粘贴下面的相关代码段:
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
答案 0 :(得分:2)
没有区别,两种方法都会以同样的方式挂钩__getitem__
。
>>> class Thing(object):
... def __getitem__(self, item):
... print(repr(item))
...
>>> t = Thing()
>>> t[0:, 4]
(slice(0, None, None), 4)
>>> t[0::, 4]
(slice(0, None, None), 4)