NumPy Logic functions: isfortran() function
numpy.isfortran() function
The isfortran() function is used to returns True if the array is Fortran contiguous but not C contiguous.
This function is obsolete and, because of changes due to relaxed stride checking,
its return value for the same array may differ for versions of NumPy >= 1.10.0 and previous versions.
If you only want to check if an array is Fortran contiguous use a.flags.f_contiguous instead.
Syntax:
numpy.isfortran(a)
Version: 1.15.0
Parameter:
Name | Description | Required / Optional |
---|---|---|
a | Input array. ndarray |
Required |
Returns:
all : ndarray, bool - A new boolean or array is returned unless out is specified, in which case a reference to out is returned.
NumPy.isfortran() method Example:
np.array allows to specify whether the array is written in C-contiguous order (last index varies the fastest),
or FORTRAN-contiguous order in memory (first index varies the fastest).
>>> import numpy as np
>>> x = np.array([[1, 3, 5], [2, 4, 6]], order='C')
>>> x
Output:
array([[1, 3, 5], [2, 4, 6]])
>>> import numpy as np
>>> x = np.array([[1, 3, 5], [2, 4, 6]], order='C')
>>> np.isfortran(x)
Output:
False
>>> import numpy as np
>>> y = np.array([[1, 3, 5], [2, 4, 6]], order='F') # FORTRAN = 'F'
>>> y
Output:
array([[1, 3, 5], [2, 4, 6]])
>>> import numpy as np
>>> y = np.array([[1, 2, 3], [4, 5, 6]], order='F') # FORTRAN = 'F'
>>> np.isfortran(y)
Output:
True
The transpose of a C-ordered array is a FORTRAN-ordered array.
>>> import numpy as np
>>> x = np.array([[1, 2, 3], [4, 5, 6]], order='C')
>>> x
Output:
array([[1, 2, 3], [4, 5, 6]])
The transpose of a C-ordered array is a FORTRAN-ordered array.
>>> import numpy as np
>>> x = np.array([[1, 3, 5], [2, 4, 6]], order='C')
>>> np.isfortran(x)
Output:
False
>>> import numpy as np
>>> x = np.array([[1, 3, 5], [2, 4, 6]], order='C')
>>> y = x.T
>>> y
Output:
array([[1, 2], [3, 4], [5, 6]])
>>> import numpy as np
>>> x = np.array([[1, 3, 5], [2, 4, 6]], order='C')
>>> y = x.T
>>> np.isfortran(y)
Output:
True
C-ordered arrays evaluate as False even if they are also FORTRAN-ordered.
>>> import numpy as np
>>> np.isfortran(np.array([1, 5], order='F')) # FORTRAN = 'F'
Output:
False
Python - NumPy Code Editor:
Previous: iscomplexobj() function
Next: isreal() function
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/numpy/logic-functions/isfortran.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics