2016-07-06 3 views
2

나는 파이썬과 NumPy를 사용하여이 문제를 해결하고있는 Kaggle Titanic tutorial을 따르려고합니다. 나는 데이터 [0 ::,]와 데이터 [0 :,]의 차이점을 이해하는데 어려움을 겪고있다. 차이가 없습니다numpy 배열을 필터링 할 때 0 :: 및 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 
+2

결과가 변경되는지 확인하기 위해 전환을 시도 했습니까? 둘 다 슬라이스에서 기본'stop'과'step'을 사용하고 있습니다. – jonrsharpe

+0

@wim ah 사실입니다.이 튜토리얼에서는 2.7을 사용하고 있습니다. 'numpy'가 실제로 그렇게합니까? – jonrsharpe

+0

아니, 나는 OP의 경우 터플로 항상 getitem이기 때문에 착각했다. – wim

답변

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) 
+0

따라서 0 대신 0을 사용하면 아무런 해가 없습니다. – gyurisc