numpy.asfortranarray#

numpy.asfortranarray(a,dtype=None,*,like=None)#

Return an array (ndim >= 1) laid out in Fortran order in memory.

Parameters:
aarray_like

Input array.

dtypestr or dtype object, optional

By default, the data-type is inferred from the input data.

likearray_like, optional

Reference object to allow the creation of arrays which are notNumPy arrays. If an array-like passed in aslike supportsthe__array_function__ protocol, the result will be definedby it. In this case, it ensures the creation of an array objectcompatible with that passed in via this argument.

New in version 1.20.0.

Returns:
outndarray

The inputa in Fortran, or column-major, order.

See also

ascontiguousarray

Convert input to a contiguous (C order) array.

asanyarray

Convert input to an ndarray with either row or column-major memory order.

require

Return an ndarray that satisfies requirements.

ndarray.flags

Information about the memory layout of the array.

Examples

Starting with a C-contiguous array:

>>>importnumpyasnp>>>x=np.ones((2,3),order='C')>>>x.flags['C_CONTIGUOUS']True

Callingasfortranarray makes a Fortran-contiguous copy:

>>>y=np.asfortranarray(x)>>>y.flags['F_CONTIGUOUS']True>>>np.may_share_memory(x,y)False

Now, starting with a Fortran-contiguous array:

>>>x=np.ones((2,3),order='F')>>>x.flags['F_CONTIGUOUS']True

Then, callingasfortranarray returns the same object:

>>>y=np.asfortranarray(x)>>>xisyTrue

Note: This function returns an array with at least one-dimension (1-d)so it will not preserve 0-d arrays.

On this page