From 32b3580687cb4d898007ae52cfa1c38281a68837 Mon Sep 17 00:00:00 2001 From: Wirawan Purwanto Date: Wed, 20 May 2015 09:50:38 -0400 Subject: [PATCH] * Added array_tools.array_vstack. --- array_tools.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/array_tools.py b/array_tools.py index 04b2ec7..3c0e3cf 100644 --- a/array_tools.py +++ b/array_tools.py @@ -61,3 +61,27 @@ def array_hstack(arrays): return hstack(stk) +def array_vstack(arrays): + """Creates a 2D array by vertically stacking many arrays together + (along the array's first dimension). + Each of the input arrays can be a 1D or 2D array. + This function is similar to numpy.vstack. + """ + from numpy import asarray, vstack + stk = [] + + for a1 in arrays: + a = asarray(a1) + dim = len(a.shape) + if dim == 1: + a = a.reshape((1,len(a))) + elif dim == 2: + pass + else: + raise ValueError, "Won't take 3D, 4D, ... arrays" + + stk.append(a) + + return vstack(stk) + +