w3resource

NumPy: Create and display every element of a numpy array

NumPy: Array Object Exercise-70 with Solution

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

Sample Solution:

Python Code:

import numpy as np
x = np.arange(12).reshape(3, 4)
for x in np.nditer(x):
    print(x,end=' ')
print()

Sample Output:

0 1 2 3 4 5 6 7 8 9 10 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 an array with 10^3 elements.
Next: Write a NumPy program to create and display every element of a numpy array in Fortran order.

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}