$42 GRAYBYTE WORDPRESS FILE MANAGER $14

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/cloudlinux/venv/lib/python3.11/site-packages/numpy/core/

HOME
Current File : /opt/cloudlinux/venv/lib/python3.11/site-packages/numpy/core//_asarray.py
"""
Functions in the ``as*array`` family that promote array-likes into arrays.

`require` fits this category despite its name not matching this pattern.
"""
from .overrides import (
    array_function_dispatch,
    set_array_function_like_doc,
    set_module,
)
from .multiarray import array, asanyarray


__all__ = ["require"]


POSSIBLE_FLAGS = {
    'C': 'C', 'C_CONTIGUOUS': 'C', 'CONTIGUOUS': 'C',
    'F': 'F', 'F_CONTIGUOUS': 'F', 'FORTRAN': 'F',
    'A': 'A', 'ALIGNED': 'A',
    'W': 'W', 'WRITEABLE': 'W',
    'O': 'O', 'OWNDATA': 'O',
    'E': 'E', 'ENSUREARRAY': 'E'
}


@set_array_function_like_doc
@set_module('numpy')
def require(a, dtype=None, requirements=None, *, like=None):
    """
    Return an ndarray of the provided type that satisfies requirements.

    This function is useful to be sure that an array with the correct flags
    is returned for passing to compiled code (perhaps through ctypes).

    Parameters
    ----------
    a : array_like
       The object to be converted to a type-and-requirement-satisfying array.
    dtype : data-type
       The required data-type. If None preserve the current dtype. If your
       application requires the data to be in native byteorder, include
       a byteorder specification as a part of the dtype specification.
    requirements : str or sequence of str
       The requirements list can be any of the following

       * 'F_CONTIGUOUS' ('F') - ensure a Fortran-contiguous array
       * 'C_CONTIGUOUS' ('C') - ensure a C-contiguous array
       * 'ALIGNED' ('A')      - ensure a data-type aligned array
       * 'WRITEABLE' ('W')    - ensure a writable array
       * 'OWNDATA' ('O')      - ensure an array that owns its own data
       * 'ENSUREARRAY', ('E') - ensure a base array, instead of a subclass
    ${ARRAY_FUNCTION_LIKE}

        .. versionadded:: 1.20.0

    Returns
    -------
    out : ndarray
        Array with specified requirements and type if given.

    See Also
    --------
    asarray : Convert input to an ndarray.
    asanyarray : Convert to an ndarray, but pass through ndarray subclasses.
    ascontiguousarray : Convert input to a contiguous array.
    asfortranarray : Convert input to an ndarray with column-major
                     memory order.
    ndarray.flags : Information about the memory layout of the array.

    Notes
    -----
    The returned array will be guaranteed to have the listed requirements
    by making a copy if needed.

    Examples
    --------
    >>> x = np.arange(6).reshape(2,3)
    >>> x.flags
      C_CONTIGUOUS : True
      F_CONTIGUOUS : False
      OWNDATA : False
      WRITEABLE : True
      ALIGNED : True
      WRITEBACKIFCOPY : False

    >>> y = np.require(x, dtype=np.float32, requirements=['A', 'O', 'W', 'F'])
    >>> y.flags
      C_CONTIGUOUS : False
      F_CONTIGUOUS : True
      OWNDATA : True
      WRITEABLE : True
      ALIGNED : True
      WRITEBACKIFCOPY : False

    """
    if like is not None:
        return _require_with_like(
            like,
            a,
            dtype=dtype,
            requirements=requirements,
        )

    if not requirements:
        return asanyarray(a, dtype=dtype)

    requirements = {POSSIBLE_FLAGS[x.upper()] for x in requirements}

    if 'E' in requirements:
        requirements.remove('E')
        subok = False
    else:
        subok = True

    order = 'A'
    if requirements >= {'C', 'F'}:
        raise ValueError('Cannot specify both "C" and "F" order')
    elif 'F' in requirements:
        order = 'F'
        requirements.remove('F')
    elif 'C' in requirements:
        order = 'C'
        requirements.remove('C')

    arr = array(a, dtype=dtype, order=order, copy=False, subok=subok)

    for prop in requirements:
        if not arr.flags[prop]:
            return arr.copy(order)
    return arr


_require_with_like = array_function_dispatch()(require)

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
14 Aug 2025 9.24 PM
root / root
0755
__pycache__
--
14 Aug 2025 9.25 PM
root / root
0755
include
--
17 Apr 2025 8.10 PM
root / root
0755
lib
--
14 Aug 2025 9.24 PM
root / root
0755
tests
--
14 Aug 2025 9.24 PM
root / root
0755
__init__.py
5.644 KB
17 Apr 2025 8.10 PM
root / root
0644
__init__.pyi
0.123 KB
17 Apr 2025 8.10 PM
root / root
0644
_add_newdocs.py
204.074 KB
17 Apr 2025 8.10 PM
root / root
0644
_add_newdocs_scalars.py
11.822 KB
17 Apr 2025 8.10 PM
root / root
0644
_asarray.py
3.793 KB
17 Apr 2025 8.10 PM
root / root
0644
_asarray.pyi
1.061 KB
17 Apr 2025 8.10 PM
root / root
0644
_dtype.py
10.357 KB
17 Apr 2025 8.10 PM
root / root
0644
_dtype_ctypes.py
3.587 KB
17 Apr 2025 8.10 PM
root / root
0644
_exceptions.py
5.253 KB
17 Apr 2025 8.10 PM
root / root
0644
_internal.py
27.684 KB
17 Apr 2025 8.10 PM
root / root
0644
_internal.pyi
1.008 KB
17 Apr 2025 8.10 PM
root / root
0644
_machar.py
11.294 KB
17 Apr 2025 8.10 PM
root / root
0644
_methods.py
8.411 KB
17 Apr 2025 8.10 PM
root / root
0644
_multiarray_tests.cpython-311-x86_64-linux-gnu.so
171.398 KB
17 Apr 2025 8.11 PM
root / root
0755
_multiarray_umath.cpython-311-x86_64-linux-gnu.so
6.64 MB
17 Apr 2025 8.11 PM
root / root
0755
_operand_flag_tests.cpython-311-x86_64-linux-gnu.so
16.547 KB
17 Apr 2025 8.11 PM
root / root
0755
_rational_tests.cpython-311-x86_64-linux-gnu.so
58.289 KB
17 Apr 2025 8.11 PM
root / root
0755
_simd.cpython-311-x86_64-linux-gnu.so
2.47 MB
17 Apr 2025 8.11 PM
root / root
0755
_string_helpers.py
2.785 KB
17 Apr 2025 8.10 PM
root / root
0644
_struct_ufunc_tests.cpython-311-x86_64-linux-gnu.so
16.648 KB
17 Apr 2025 8.11 PM
root / root
0755
_type_aliases.py
7.357 KB
17 Apr 2025 8.10 PM
root / root
0644
_type_aliases.pyi
0.395 KB
17 Apr 2025 8.10 PM
root / root
0644
_ufunc_config.py
13.617 KB
17 Apr 2025 8.10 PM
root / root
0644
_ufunc_config.pyi
1.041 KB
17 Apr 2025 8.10 PM
root / root
0644
_umath_tests.cpython-311-x86_64-linux-gnu.so
41.008 KB
17 Apr 2025 8.11 PM
root / root
0755
arrayprint.py
62.117 KB
17 Apr 2025 8.10 PM
root / root
0644
arrayprint.pyi
4.324 KB
17 Apr 2025 8.10 PM
root / root
0644
cversions.py
0.339 KB
17 Apr 2025 8.10 PM
root / root
0644
defchararray.py
71.892 KB
17 Apr 2025 8.10 PM
root / root
0644
defchararray.pyi
9 KB
17 Apr 2025 8.10 PM
root / root
0644
einsumfunc.py
50.652 KB
17 Apr 2025 8.10 PM
root / root
0644
einsumfunc.pyi
4.746 KB
17 Apr 2025 8.10 PM
root / root
0644
fromnumeric.py
125.802 KB
17 Apr 2025 8.10 PM
root / root
0644
fromnumeric.pyi
22.959 KB
17 Apr 2025 8.10 PM
root / root
0644
function_base.py
19.371 KB
17 Apr 2025 8.10 PM
root / root
0644
function_base.pyi
4.614 KB
17 Apr 2025 8.10 PM
root / root
0644
generate_numpy_api.py
7.475 KB
17 Apr 2025 8.10 PM
root / root
0644
getlimits.py
25.259 KB
17 Apr 2025 8.10 PM
root / root
0644
getlimits.pyi
0.08 KB
17 Apr 2025 8.10 PM
root / root
0644
memmap.py
11.495 KB
17 Apr 2025 8.10 PM
root / root
0644
memmap.pyi
0.054 KB
17 Apr 2025 8.10 PM
root / root
0644
multiarray.py
54.782 KB
17 Apr 2025 8.10 PM
root / root
0644
multiarray.pyi
24.188 KB
17 Apr 2025 8.10 PM
root / root
0644
numeric.py
75.209 KB
17 Apr 2025 8.10 PM
root / root
0644
numeric.pyi
13.896 KB
17 Apr 2025 8.10 PM
root / root
0644
numerictypes.py
17.674 KB
17 Apr 2025 8.10 PM
root / root
0644
numerictypes.pyi
3.19 KB
17 Apr 2025 8.10 PM
root / root
0644
overrides.py
6.927 KB
17 Apr 2025 8.10 PM
root / root
0644
records.py
36.653 KB
17 Apr 2025 8.10 PM
root / root
0644
records.pyi
5.559 KB
17 Apr 2025 8.10 PM
root / root
0644
setup.py
47.053 KB
17 Apr 2025 8.10 PM
root / root
0644
setup_common.py
16.685 KB
17 Apr 2025 8.10 PM
root / root
0644
shape_base.py
29.046 KB
17 Apr 2025 8.10 PM
root / root
0644
shape_base.pyi
2.709 KB
17 Apr 2025 8.10 PM
root / root
0644
umath.py
1.992 KB
17 Apr 2025 8.10 PM
root / root
0644
umath_tests.py
0.38 KB
17 Apr 2025 8.10 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF