Perform the following operations to Manipulating the Dimensions and the Shape of Arrays(Joining and Stacking). Data science using Python in Anaconda - Jupyter

 Question 

array1 = np.array([[1, 2, 3], [4, 5, 6]])

array2 = np.array([[7, 8, 9], [10, 11, 12]])

1. Stack arrays in sequence horizontally (column wise).

2. Stack arrays in sequence vertically (row wise)

3. Stack arrays in sequence depth wise (along third axis)

4. Appending arrays after each other, along a given axis

5. Append values to the end of an array


Program: -

import numpy as np
array1 = np.array([[123], [456]])
array2 = np.array([[789], [101112]])
print("Orignal Array 1:- \n",array1,"\n")
print("Orignal Array 2:- \n",array2,"\n")
print("Stack arrays in sequence horizontally (column wise). :- \n",np.hstack((array1,array2)))
print("Stack arrays in sequence vertically (row wise) :- \n",np.vstack((array1,array2)))
print("Stack arrays in sequence depth wise (along third axis) :- \n",np.dstack((array1,array2)))
print("Appending arrays after each other, along a given axis :- \n",np.append(array1,array2,1))
print("Append values to the end of an array :- \n",np.append(array1,array2))


Output: -
Orignal Array 1:- [[1 2 3] [4 5 6]] Orignal Array 2:- [[ 7 8 9] [10 11 12]] Stack arrays in sequence horizontally (column wise). :- [[ 1 2 3 7 8 9] [ 4 5 6 10 11 12]] Stack arrays in sequence vertically (row wise) :- [[ 1 2 3] [ 4 5 6] [ 7 8 9] [10 11 12]] Stack arrays in sequence depth wise (along third axis) :- [[[ 1 7] [ 2 8] [ 3 9]] [[ 4 10] [ 5 11] [ 6 12]]] Appending arrays after each other, along a given axis :- [[ 1 2 3 7 8 9] [ 4 5 6 10 11 12]] Append values to the end of an array :- [ 1 2 3 4 5 6 7 8 9 10 11 12]