You are on page 1of 2

Stacking arrays

Description
Merge the three arrays provided to you to form a one 4x4 array.

[Hint: Check the function np.transpose() in the 'Manipulating Arrays' notebook


provided.]

Input:

Array 1: 3*3

[[7, 13, 14]

[18, 10, 17]

[11, 12, 19]]

Array 2: 1-D array

[16, 6, 1]

Array 3: 1*4 array

[[5, 8, 4, 3]]

Output:

[[7 13 14 5]

[18 10 17 8]

[11 12 19 4]

[16 6 1 3]]

# Read the input


import ast,sys
input_str = sys.stdin.read()
input_list = ast.literal_eval(input_str)
list_1 = input_list[0]
list_2 = input_list[1]
list_3 = input_list[2]

# Import NumPy
import numpy as np

# Convert the second and third arrays to 2D arrays


array_2 = np.reshape(list_2, (1,3))
array_3 = np.transpose(list_3)

# Create an empty 4x4 array


final_array = np.zeros((4,4), dtype=int)

# Fill the first three columns of the first three rows with values from the first
array
final_array[:3, :3] = np.array(list_1)

# Fill the last row with values from the second array
final_array[3, :3] = array_2

# Fill the last column with values from the third array
final_array[:3, 3] = array_3

# Print the final array


print(final_array)

You might also like