Esempio n. 1
0
def uarray(nominal_values, std_devs=None):
    """
    Returns a NumPy array of numbers with uncertainties
    initialized with the given nominal values and standard
    deviations.

    nominal_values, std_devs -- valid arguments for numpy.array, with
    identical shapes (list of numbers, list of lists, numpy.ndarray,
    etc.).

    std_devs=None is only used for supporting legacy code, where
    nominal_values can be the tuple of nominal values and standard
    deviations.
    """

    if std_devs is None:  # Obsolete, single tuple argument call
        deprecation('uarray() should now be called with two arguments.')
        (nominal_values, std_devs) = nominal_values
        
    return (numpy.vectorize(
        # ! Looking up uncertainties.Variable beforehand through
        # '_Variable = uncertainties.Variable' does not result in a
        # significant speed up:
        lambda v, s: uncertainties.Variable(v, s), otypes=[object])
        (nominal_values, std_devs))
Esempio n. 2
0
def uarray(nominal_values, std_devs=None):
    """
    Returns a NumPy array of numbers with uncertainties
    initialized with the given nominal values and standard
    deviations.

    nominal_values, std_devs -- valid arguments for numpy.array, with
    identical shapes (list of numbers, list of lists, numpy.ndarray,
    etc.).

    std_devs=None is only used for supporting legacy code, where
    nominal_values can be the tuple of nominal values and standard
    deviations.
    """

    if std_devs is None:  # Obsolete, single tuple argument call
        deprecation('uarray() should now be called with two arguments.')
        (nominal_values, std_devs) = nominal_values

    return (numpy.vectorize(
        # ! Looking up uncertainties.Variable beforehand through
        # '_Variable = uncertainties.Variable' does not result in a
        # significant speed up:
        lambda v, s: uncertainties.Variable(v, s),
        otypes=[object])(nominal_values, std_devs))
Esempio n. 3
0
def umatrix(nominal_values, std_devs=None):
    """
    Constructs a matrix that contains numbers with uncertainties.

    The arguments are the same as for uarray(...): nominal values, and
    standard deviations.

    The returned matrix can be inverted, thanks to the fact that it is
    a unumpy.matrix object instead of a numpy.matrix one.
    """

    if std_devs is None:  # Obsolete, single tuple argument call
        deprecation('umatrix() should now be called with two arguments.')
        (nominal_values, std_devs) = nominal_values
            
    return uarray(nominal_values, std_devs).view(matrix)
Esempio n. 4
0
def umatrix(nominal_values, std_devs=None):
    """
    Constructs a matrix that contains numbers with uncertainties.

    The arguments are the same as for uarray(...): nominal values, and
    standard deviations.

    The returned matrix can be inverted, thanks to the fact that it is
    a unumpy.matrix object instead of a numpy.matrix one.
    """

    if std_devs is None:  # Obsolete, single tuple argument call
        deprecation('umatrix() should now be called with two arguments.')
        (nominal_values, std_devs) = nominal_values

    return uarray(nominal_values, std_devs).view(matrix)