@@ -562,7 +562,7 @@ def expand_subpaths(self):
562562 path_slice = path [s :s + k + 1 ]
563563 self .paths [k ][path_slice ][0 ] += frequency
564564
565- def add_path_tuple (self , path , expand_subpaths = True , frequency = np . array ([ 0 , 1 ] )):
565+ def add_path_tuple (self , path , expand_subpaths = True , frequency = ( 0 , 1 )):
566566 """Adds a tuple of elements as a path. If the elements are not strings,
567567 a conversion to strings will be made. This function can be used to
568568 to set custom subpath statistics, via the frequency tuple (see below).
@@ -605,7 +605,7 @@ def add_path_tuple(self, path, expand_subpaths=True, frequency=np.array([0, 1]))
605605 for i in range (s , s + k + 1 ):
606606 subpath += (path_str [i ],)
607607 # add subpath weight to first component of occurrences
608- self .paths [k ][subpath ] += np . array ([ frequency [1 ], 0 ])
608+ self .paths [k ][subpath ][ 0 ] += frequency [1 ]
609609
610610 def add_path_ngram (self , ngram , separator = ',' , expand_subpaths = True , frequency = None ):
611611 """Adds the path(s) of a single n-gram to the path statistics object.
@@ -639,20 +639,20 @@ def add_path_ngram(self, ngram, separator=',', expand_subpaths=True, frequency=N
639639
640640 # add the occurrences as *longest* path to the second component of the numpy array
641641 if frequency is not None :
642- self .paths [path_length ][path ] += np . array ([ 0 , frequency ])
642+ self .paths [path_length ][path ][ 1 ] += frequency
643643 else :
644- self .paths [path_length ][path ] += np . array ([ 0 , 1 ])
644+ self .paths [path_length ][path ][ 1 ] += 1
645645
646646 if expand_subpaths :
647647 max_length = min (self .max_subpath_length + 1 , len (path ) - 1 )
648648 if frequency is not None :
649649 for k in range (max_length ):
650650 for s in range (path_length - k + 1 ):
651- self .paths [k ][path [s :s + k + 1 ]] += np . array ([ frequency , 0 ])
651+ self .paths [k ][path [s :s + k + 1 ]][ 0 ] += frequency
652652 else :
653653 for k in range (max_length ):
654654 for s in range (path_length - k + 1 ):
655- self .paths [k ][path [s :s + k + 1 ]] += np . array ([ 1 , 0 ])
655+ self .paths [k ][path [s :s + k + 1 ]][ 0 ] += 1
656656
657657 @staticmethod
658658 def contained_paths (p , node_filter ):
0 commit comments