python - What is the difference between 0:: and 0: when filtering a numpy array? -
this question has answer here:
- python: single colon vs double colon 5 answers
i trying follow kaggle titanic tutorial solving problem using python , numpy. having difficulties understanding difference between data[0::, ] , data[0:, ]. copy paste relevant code snippet below:
for in xrange(number_of_classes):       #loop through each class     j in xrange(number_of_price_brackets):   #loop through each price bin          women_only_stats = data[                          # element                                            (data[0::, 4] == "female") &   # female ,                                 (data[0::, 2].astype(np.float) # ith class                                   == i+1)                                  &                              # ,                                 (data[0:, 9].astype(np.float)  # greater                                   >= j * fare_bracket_size)    # bin                                  &                              # ,                                (data[0:, 9].astype(np.float)   # less                                   < (j+1)*fare_bracket_size)   # next bin                                    , 1]                        # in 2nd col  
there no difference, both methods hook __getitem__ in same way.
>>> 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) 
Comments
Post a Comment