PIXELBANKv8.2.1
Menu

Array Stacking

Problem Statement

Combine multiple arrays using stacking operations.

Background

NumPy provides several stacking functions:

  • np.vstack - vertical stack (row-wise)
  • np.hstack - horizontal stack (column-wise)
  • np.concatenate - general concatenation
  • np.stack - stack along new axis

Your Task

Write a function stack_arrays(arr1, arr2) that combines two 1D arrays.

Output Format

Return a dictionary with:

  • "vertical": vstack result (2 rows) as list
  • "horizontal": hstack result (1 longer row) as list
  • "as_columns": Side by side as columns as list

Example:

Input:
arr1 = [1, 2, 3], arr2 = [4, 5, 6]
Output:
{'vertical': [[1, 2, 3], [4, 5, 6]], 'horizontal': [1, 2, 3, 4, 5, 6], 'as_columns': [[1, 4], [2, 5], [3, 6]]}
Reasoning:

vstack creates rows, hstack concatenates, column_stack pairs elements

Constraints:

  • Both arrays have the same length
  • Arrays are 1D
Editor

Test Results

0/0
Run code to see test results.