w3resource

NumPy Array manipulation: asfortranarrray() function

numpy.asfortranarrray() function

The asfortranarrray() function is used to get an array laid out in Fortran order in memory.

Syntax:

numpy.asfortranarray(a, dtype=None)

Version: 1.15.0

Parameter:

Name Description Required /
Optional
a Input array. Required
dtype By default, the data-type is inferred from the input data. Optional

Return value:

out : ndarray The input a in Fortran, or column-major, order.

Example: numpy.asfortranarrray()

>>> import numpy as np
>>> a = np.arange(9).reshape(3,3)
>>> b = np.asfortranarray(a)
>>> a.flags['F_CONTIGUOUS']
False
>>> b.flags['F_CONTIGUOUS']
True

Python - NumPy Code Editor:

Previous: asfarray()
Next: ascontiguousarray()