w3resource

NumPy: Create and display every element of a numpy array in Fortran order

NumPy: Array Object Exercise-71 with Solution

Write a NumPy program to create and display every element of a numpy array in Fortran order.

Sample Solution:

Python Code:

import numpy as np
x = np.arange(12).reshape(3, 4)
print("Elements of the array in Fortan array:")
for x in np.nditer(x, order="F"):
    print(x,end=' ')
print("\n")

Sample Output:

Elements of the array in Fortan array:                                 
0 4 8 1 5 9 2 6 10 3 7 11   

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a NumPy program to create and display every element of a numpy array.
Next: Write a NumPy program to create a 5x5x5 cube of 1's.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

Set comprehension:

>>> m = {x ** 2 for x in range(5)}
>>> m
{0, 1, 4, 9, 16}