You are viewing an older version (2.4.3). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.4.3 / 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_like

Input array.

dtype : str or dtype object, optional

Data-type of returned array.

like : array_like, optional

Reference object to allow the creation of arrays which are not NumPy arrays. If an array-like passed in as like supports 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 : ndarray

Contiguous array of same shape and content as a, with type dtype if specified.

Examples

Starting with a Fortran-contiguous array:
import numpy as np
x = np.ones((2, 3), order='F')
x.flags['F_CONTIGUOUS']
Calling ``ascontiguousarray`` makes a C-contiguous copy:
y = np.ascontiguousarray(x)
y.flags['C_CONTIGUOUS']
np.may_share_memory(x, y)
Now, starting with a C-contiguous array:
x = np.ones((2, 3), order='C')
x.flags['C_CONTIGUOUS']
Then, calling ``ascontiguousarray`` returns the same object:
y = np.ascontiguousarray(x)
x is y
Note: This function returns an array with at least one-dimension (1-d) so it will not preserve 0-d arrays.

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