Esempio n. 1
0
def vdot(a, b):
    """Returns the dot product of 2 vectors (or anything that can be made into
    a vector). NB: this is not the same as `dot`, as it takes the conjugate
    of its first argument if complex and always returns a scalar."""
    a, b = _na.ravel(a), _na.ravel(b)
    try:
        return _dotblas.vdot(a, b)
    # in case we get an integer Value
    except TypeError:
        return _numarray.dot(a, b)
Esempio n. 2
0
def vdot(a, b):
    """Returns the dot product of 2 vectors (or anything that can be made into
    a vector). NB: this is not the same as `dot`, as it takes the conjugate
    of its first argument if complex and always returns a scalar."""
    a, b = _na.ravel(a), _na.ravel(b)
    try:
        return _dotblas.vdot(a, b)
    # in case we get an integer Value
    except TypeError:
        return _numarray.dot(a, b)
Esempio n. 3
0
    def eval(self):
        """eval(self) converts CharArray 'self' into a NumArray.
        This is the original slow implementation based on a Python loop
        and the eval() function.

        >>> array([["1","2"],["3","4"]]).eval()
        array([[1, 2],
               [3, 4]])
        >>> try:
        ...    array([["1","2"],["3","other"]]).eval()
        ... except NameError:
        ...    pass
        """
        n = _na.array([eval(x, {}, {}) for x in _na.ravel(self)])
        n.setshape(self._shape)
        return n
Esempio n. 4
0
    def __contains__(self, str):
        """
        Returns 1 if-and-only-if 'self' has an element == to 'str'

        >>> s=array(["this ", "thar", "other"])
        >>> int("this" in s)
        1
        >>> int("tjt" in s)
        0
        >>> x=array([""])
        >>> int("this" in x)
        0
        >>> int("" in x)
        1
        """
        return _na.logical_or.reduce(_na.ravel(self.__eq__(str)))
Esempio n. 5
0
    def eval(self):
        """eval(self) converts CharArray 'self' into a NumArray.
        This is the original slow implementation based on a Python loop
        and the eval() function.

        >>> array([["1","2"],["3","4"]]).eval()
        array([[1, 2],
               [3, 4]])
        >>> try:
        ...    array([["1","2"],["3","other"]]).eval()
        ... except NameError:
        ...    pass
        """
        n = _na.array([eval(x, {}, {}) for x in _na.ravel(self)])
        n.setshape(self._shape)
        return n
Esempio n. 6
0
    def __contains__(self, str):
        """
        Returns 1 if-and-only-if 'self' has an element == to 'str'

        >>> s=array(["this ", "thar", "other"])
        >>> int("this" in s)
        1
        >>> int("tjt" in s)
        0
        >>> x=array([""])
        >>> int("this" in x)
        0
        >>> int("" in x)
        1
        """
        return _na.logical_or.reduce(_na.ravel(self.__eq__(str)))
Esempio n. 7
0
def mask(a, m):
    """mask(a, m) returns the values of 'a' satisfying category 'm'.
    mask does a parallel check for values which are not classifyable
    by the categorization code, raising a RuntimeError exception if
    any are found.
    """
    a = _na.asarray(a)
    if isinstance(a.type(), _na.IntegralType):
        a = a.astype('Float64')
    if isinstance(a.type(), _na.ComplexType):
        f = _na.ieeemask(a.real, m) | _na.ieeemask(a.imag, m)
        g = _na.ieeemask(a.real, BUG) | _na.ieeemask(a.imag, BUG)
    else:
        f = _na.ieeemask(a, m)
        g = _na.ieeemask(a, BUG)
    if _na.bitwise_or.reduce(_na.ravel(g)) != 0:
        raise RuntimeError("Unclassifyable floating point values.")
    if f.rank == 0:
        f = f[()]
    return f
Esempio n. 8
0
def mask(a, m):
    """mask(a, m) returns the values of 'a' satisfying category 'm'.
    mask does a parallel check for values which are not classifyable
    by the categorization code, raising a RuntimeError exception if
    any are found.
    """
    a = _na.asarray(a)
    if isinstance(a.type(), _na.IntegralType):
        a = a.astype('Float64')
    if isinstance(a.type(), _na.ComplexType):
        f = _na.ieeemask(a.real, m) | _na.ieeemask(a.imag, m)
        g = _na.ieeemask(a.real, BUG) | _na.ieeemask(a.imag, BUG)
    else:
        f = _na.ieeemask(a, m)
        g = _na.ieeemask(a, BUG)
    if _na.bitwise_or.reduce(_na.ravel(g)) != 0:
        raise RuntimeError("Unclassifyable floating point values.")
    if f.rank == 0:
        f = f[()]
    return f