Write a NumPy program to combine a one and a two dimensional array together and display their elements.
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
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer