﻿ NumPy: Stack arrays in sequence horizontally - w3resource # NumPy: Stack arrays in sequence horizontally

## NumPy: Array Object Exercise-127 with Solution

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

Pictorial Presentation: Sample Solution:

Python Code:

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

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