Q:

Write a NumPy program to join a sequence of arrays along a new axis

0

Write a NumPy program to join a sequence of arrays along a new axis.

All Answers

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

import numpy as np    
x = np.array([1, 2, 3])
y = np.array([2, 3, 4])
print("Original arrays:")
print(x)
print(y)
print("Sequence of arrays along a new axis:")
print(np.vstack((x, y)))
x = np.array([[1], [2], [3]])
y = np.array([[2], [3], [4]])
print("\nOriginal arrays:")
print(x)
print()
print(y)
print("Sequence of arrays along a new axis:")
print(np.vstack((x, y)))

Sample Output:

Original arrays:
[1 2 3]
[2 3 4]
Sequence of arrays along a new axis:
[[1 2 3]
 [2 3 4]]

Original arrays:
[[1]
 [2]
 [3]]

[[2]
 [3]
 [4]]
Sequence of arrays along a new axis:
[[1]
 [2]
 [3]
 [2]
 [3]
 [4]]

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