﻿ NumPy: Join a sequence of arrays along a new axis - w3resource # NumPy: Join a sequence of arrays along a new axis

## NumPy: Array Object Exercise-121 with Solution

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

Sample Solution:

Python Code:

``````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([, , ])
y = np.array([, , ])
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:
[

]

[

]
Sequence of arrays along a new axis:
[




]
```

Pictorial Presentation: Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

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}
```