$29 GRAYBYTE WORDPRESS FILE MANAGER $64

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/alt/python37/lib64/python3.7/site-packages/numpy/core/

HOME
Current File : /opt/alt/python37/lib64/python3.7/site-packages/numpy/core//_methods.py
"""
Array methods which are called by both the C-code for the method
and the Python code for the NumPy-namespace function

"""
from __future__ import division, absolute_import, print_function

import warnings

from numpy.core import multiarray as mu
from numpy.core import umath as um
from numpy.core.numeric import asanyarray
from numpy.core import numerictypes as nt

# save those O(100) nanoseconds!
umr_maximum = um.maximum.reduce
umr_minimum = um.minimum.reduce
umr_sum = um.add.reduce
umr_prod = um.multiply.reduce
umr_any = um.logical_or.reduce
umr_all = um.logical_and.reduce

# avoid keyword arguments to speed up parsing, saves about 15%-20% for very
# small reductions
def _amax(a, axis=None, out=None, keepdims=False):
    return umr_maximum(a, axis, None, out, keepdims)

def _amin(a, axis=None, out=None, keepdims=False):
    return umr_minimum(a, axis, None, out, keepdims)

def _sum(a, axis=None, dtype=None, out=None, keepdims=False):
    return umr_sum(a, axis, dtype, out, keepdims)

def _prod(a, axis=None, dtype=None, out=None, keepdims=False):
    return umr_prod(a, axis, dtype, out, keepdims)

def _any(a, axis=None, dtype=None, out=None, keepdims=False):
    return umr_any(a, axis, dtype, out, keepdims)

def _all(a, axis=None, dtype=None, out=None, keepdims=False):
    return umr_all(a, axis, dtype, out, keepdims)

def _count_reduce_items(arr, axis):
    if axis is None:
        axis = tuple(range(arr.ndim))
    if not isinstance(axis, tuple):
        axis = (axis,)
    items = 1
    for ax in axis:
        items *= arr.shape[ax]
    return items

def _mean(a, axis=None, dtype=None, out=None, keepdims=False):
    arr = asanyarray(a)

    is_float16_result = False
    rcount = _count_reduce_items(arr, axis)
    # Make this warning show up first
    if rcount == 0:
        warnings.warn("Mean of empty slice.", RuntimeWarning, stacklevel=2)

    # Cast bool, unsigned int, and int to float64 by default
    if dtype is None:
        if issubclass(arr.dtype.type, (nt.integer, nt.bool_)):
            dtype = mu.dtype('f8')
        elif issubclass(arr.dtype.type, nt.float16):
            dtype = mu.dtype('f4')
            is_float16_result = True

    ret = umr_sum(arr, axis, dtype, out, keepdims)
    if isinstance(ret, mu.ndarray):
        ret = um.true_divide(
                ret, rcount, out=ret, casting='unsafe', subok=False)
        if is_float16_result and out is None:
            ret = arr.dtype.type(ret)
    elif hasattr(ret, 'dtype'):
        if is_float16_result:
            ret = arr.dtype.type(ret / rcount)
        else:
            ret = ret.dtype.type(ret / rcount)
    else:
        ret = ret / rcount

    return ret

def _var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False):
    arr = asanyarray(a)

    rcount = _count_reduce_items(arr, axis)
    # Make this warning show up on top.
    if ddof >= rcount:
        warnings.warn("Degrees of freedom <= 0 for slice", RuntimeWarning,
                      stacklevel=2)

    # Cast bool, unsigned int, and int to float64 by default
    if dtype is None and issubclass(arr.dtype.type, (nt.integer, nt.bool_)):
        dtype = mu.dtype('f8')

    # Compute the mean.
    # Note that if dtype is not of inexact type then arraymean will
    # not be either.
    arrmean = umr_sum(arr, axis, dtype, keepdims=True)
    if isinstance(arrmean, mu.ndarray):
        arrmean = um.true_divide(
                arrmean, rcount, out=arrmean, casting='unsafe', subok=False)
    else:
        arrmean = arrmean.dtype.type(arrmean / rcount)

    # Compute sum of squared deviations from mean
    # Note that x may not be inexact and that we need it to be an array,
    # not a scalar.
    x = asanyarray(arr - arrmean)
    if issubclass(arr.dtype.type, nt.complexfloating):
        x = um.multiply(x, um.conjugate(x), out=x).real
    else:
        x = um.multiply(x, x, out=x)
    ret = umr_sum(x, axis, dtype, out, keepdims)

    # Compute degrees of freedom and make sure it is not negative.
    rcount = max([rcount - ddof, 0])

    # divide by degrees of freedom
    if isinstance(ret, mu.ndarray):
        ret = um.true_divide(
                ret, rcount, out=ret, casting='unsafe', subok=False)
    elif hasattr(ret, 'dtype'):
        ret = ret.dtype.type(ret / rcount)
    else:
        ret = ret / rcount

    return ret

def _std(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False):
    ret = _var(a, axis=axis, dtype=dtype, out=out, ddof=ddof,
               keepdims=keepdims)

    if isinstance(ret, mu.ndarray):
        ret = um.sqrt(ret, out=ret)
    elif hasattr(ret, 'dtype'):
        ret = ret.dtype.type(um.sqrt(ret))
    else:
        ret = um.sqrt(ret)

    return ret

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
31 Aug 2024 3.40 AM
root / root
0755
__pycache__
--
31 Aug 2024 3.40 AM
root / root
0755
include
--
31 Aug 2024 3.40 AM
root / root
0755
lib
--
31 Aug 2024 3.40 AM
root / root
0755
tests
--
31 Aug 2024 3.40 AM
root / root
0755
__init__.py
2.968 KB
25 Apr 2023 2.30 AM
root / root
0644
_dummy.cpython-37m-x86_64-linux-gnu.so
9.07 KB
25 Apr 2023 2.38 AM
root / root
0755
_internal.py
20.874 KB
25 Apr 2023 2.30 AM
root / root
0644
_methods.py
4.594 KB
25 Apr 2023 2.30 AM
root / root
0644
arrayprint.py
28.53 KB
25 Apr 2023 2.30 AM
root / root
0644
cversions.py
0.403 KB
25 Apr 2023 2.30 AM
root / root
0644
defchararray.py
65.813 KB
25 Apr 2023 2.30 AM
root / root
0644
einsumfunc.py
34.7 KB
25 Apr 2023 2.30 AM
root / root
0644
fromnumeric.py
96.66 KB
25 Apr 2023 2.30 AM
root / root
0644
function_base.py
11.82 KB
25 Apr 2023 2.30 AM
root / root
0644
generate_numpy_api.py
7.159 KB
25 Apr 2023 2.30 AM
root / root
0644
getlimits.py
17.99 KB
25 Apr 2023 2.30 AM
root / root
0644
info.py
4.582 KB
25 Apr 2023 2.30 AM
root / root
0644
machar.py
10.536 KB
25 Apr 2023 2.30 AM
root / root
0644
memmap.py
11.164 KB
25 Apr 2023 2.30 AM
root / root
0644
multiarray.cpython-37m-x86_64-linux-gnu.so
2.29 MB
25 Apr 2023 2.38 AM
root / root
0755
multiarray_tests.cpython-37m-x86_64-linux-gnu.so
60.477 KB
25 Apr 2023 2.38 AM
root / root
0755
numeric.py
89.494 KB
25 Apr 2023 2.30 AM
root / root
0644
numerictypes.py
28.111 KB
25 Apr 2023 2.30 AM
root / root
0644
operand_flag_tests.cpython-37m-x86_64-linux-gnu.so
14.07 KB
25 Apr 2023 2.38 AM
root / root
0755
records.py
28.729 KB
25 Apr 2023 2.30 AM
root / root
0644
setup.py
39.847 KB
25 Apr 2023 2.30 AM
root / root
0644
setup_common.py
14.927 KB
25 Apr 2023 2.30 AM
root / root
0644
shape_base.py
18.634 KB
25 Apr 2023 2.30 AM
root / root
0644
struct_ufunc_test.cpython-37m-x86_64-linux-gnu.so
14.063 KB
25 Apr 2023 2.38 AM
root / root
0755
test_rational.cpython-37m-x86_64-linux-gnu.so
60.313 KB
25 Apr 2023 2.38 AM
root / root
0755
umath.cpython-37m-x86_64-linux-gnu.so
1.66 MB
25 Apr 2023 2.38 AM
root / root
0755
umath_tests.cpython-37m-x86_64-linux-gnu.so
24.602 KB
25 Apr 2023 2.38 AM
root / root
0755

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF