Ejemplo n.º 1
0
    def index(self, s):
        """index(self, s) returns the index of the first occurenced of
        's' in 'self'.

        >>> array([["this","that","another"],
        ...        ["another","this","that"]]).index("another")
        (0, 2)
        >>> array([["this","that","another"],
        ...        ["another","this","that"]]).index("not here")
        Traceback (most recent call last):
        ValueError: string 'not here' not in array

        """
        indices = _na.nonzero(self.__eq__(s))
        if len(indices[0]):
            first = map(lambda x: x[0], indices)
            return tuple(first)
        else:
            raise ValueError("string " + ` s ` + " not in array")
Ejemplo n.º 2
0
    def index(self, s):
        """index(self, s) returns the index of the first occurenced of
        's' in 'self'.

        >>> array([["this","that","another"],
        ...        ["another","this","that"]]).index("another")
        (0, 2)
        >>> array([["this","that","another"],
        ...        ["another","this","that"]]).index("not here")
        Traceback (most recent call last):
        ValueError: string 'not here' not in array

        """
        indices = _na.nonzero(self.__eq__(s))
        if len(indices[0]):
            first = map(lambda x: x[0], indices)
            return tuple(first)
        else:
            raise ValueError("string " + ` s ` + " not in array")
Ejemplo n.º 3
0
 def search(self, pattern, flags=0):
     """
     >>> a=fromlist([["wo","what"],["wen","erewh"]])
     >>> a.search("wh")
     (array([0, 1]), array([1, 1]))
     >>> a.search("1")
     (array([], type=Long), array([], type=Long))
     >>> b=array(["",""])
     >>> b.search("1")
     (array([], type=Long),)
     >>> b.search("")
     (array([0, 1]),)
     """
     searcher = re.compile(pattern, flags).search
     l = lambda x, f=searcher: int(f(x) is not None)
     matches = _na.array(self.amap(l), type=_na.Bool)
     if len(matches):
         return _na.nonzero(matches)
     else:
         return ()
Ejemplo n.º 4
0
 def search(self, pattern, flags=0):
     """
     >>> a=fromlist([["wo","what"],["wen","erewh"]])
     >>> a.search("wh")
     (array([0, 1]), array([1, 1]))
     >>> a.search("1")
     (array([], type=Long), array([], type=Long))
     >>> b=array(["",""])
     >>> b.search("1")
     (array([], type=Long),)
     >>> b.search("")
     (array([0, 1]),)
     """
     searcher = re.compile(pattern, flags).search
     l = lambda x, f=searcher: int(f(x) is not None)
     matches = _na.array(self.amap(l), type=_na.Bool)
     if len(matches):
         return _na.nonzero(matches)
     else:
         return ()
Ejemplo n.º 5
0
def getnan(a):
    """getnan returns a tuple of indices of 'a' where the values are not-a-numbers"""
    return _na.nonzero(isnan(a))
Ejemplo n.º 6
0
def index(a, msk):
    """index returns the tuple of indices where the values satisfy 'mask'"""
    return _na.nonzero(mask(a, msk))
Ejemplo n.º 7
0
def getnan(a):
    """getnan returns a tuple of indices of 'a' where the values are not-a-numbers"""
    return _na.nonzero(isnan(a))
Ejemplo n.º 8
0
def index(a, msk):
    """index returns the tuple of indices where the values satisfy 'mask'"""
    return _na.nonzero(mask(a, msk))