bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / ascontiguousarray
built-in
numpy:ascontiguousarray
Signature
built-in
ascontiguousarray ( a , dtype = None , * , like = None ) Summary
Return a contiguous array (ndim >= 1) in memory (C order).
Parameters
a: array_likeInput array.
dtype: str or dtype object, optionalData-type of returned array.
like: array_like, optionalReference object to allow the creation of arrays which are not NumPy arrays. If an array-like passed in as
likesupports the__array_function__protocol, the result will be defined by it. In this case, it ensures the creation of an array object compatible with that passed in via this argument.
Returns
out: ndarrayContiguous array of same shape and content as
a, with typedtypeif specified.
Examples
Starting with a Fortran-contiguous array:import numpy as np x = np.ones((2, 3), order='F') x.flags['F_CONTIGUOUS']✓
y = np.ascontiguousarray(x) y.flags['C_CONTIGUOUS'] np.may_share_memory(x, y)✓
x = np.ones((2, 3), order='C') x.flags['C_CONTIGUOUS']✓
y = np.ascontiguousarray(x) x is y✓
See also
- asfortranarray
Convert input to an ndarray with column-major memory order.
- ndarray.flags
Information about the memory layout of the array.
- require
Return an ndarray that satisfies requirements.
Aliases
-
numpy.ascontiguousarray