w3resource logo

:

Python Exercises

Python NumPy: Combine a one and a two dimensional array together and display their elements

Python NumPy: Array Object Exercise-74 with Solution

Write a Python program to combine a one and a two dimensional array together and display their elements.

Sample Solution:-

Python Code:

import numpy as np
x = np.arange(4)
print("One dimensional array:")
print(x)
y = np.arange(8).reshape(2,4)
print("Two dimensional array:")
print(y)
for a, b in np.nditer([x,y]):
    print("%d:%d" % (a,b),)

Sample Output:

One dimensional array:                                                 
[0 1 2 3]                                                              
Two dimensional array:                                                 
[[0 1 2 3]                                                             
 [4 5 6 7]]                                                            
0:0                                                                    
1:1                                                                    
2:2                                                                    
3:3                                                                    
0:4                                                                    
1:5                                                                    
2:6                                                                    
3:7

Python Code Editor:

Improve this sample solution and post your code through Disqus