Q:

Write a NumPy program to stack arrays in sequence horizontally (column wise)

0

Write a NumPy program to stack arrays in sequence horizontally (column wise).

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np    
print("\nOriginal arrays:")
x = np.arange(9).reshape(3,3)
y = x*3
print("Array-1")
print(x)
print("Array-2")
print(y)
new_array =  np.hstack((x,y))
print("\nStack arrays in sequence horizontally:")
print(new_array)

Sample Output:

Original arrays:
Array-1
[[0 1 2]
 [3 4 5]
 [6 7 8]]
Array-2
[[ 0  3  6]
 [ 9 12 15]
 [18 21 24]]

Stack arrays in sequence horizontally:
[[ 0  1  2  0  3  6]
 [ 3  4  5  9 12 15]
 [ 6  7  8 18 21 24]]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now