MCPcopy Create free account
hub / github.com/numpy/numpy / column_stack

Function column_stack

numpy/lib/shape_base.py:613–652  ·  view source on GitHub ↗

Stack 1-D arrays as columns into a 2-D array. Take a sequence of 1-D arrays and stack them as columns to make a single 2-D array. 2-D arrays are stacked as-is, just like with `hstack`. 1-D arrays are turned into 2-D columns first. Parameters ---------- tup : seque

(tup)

Source from the content-addressed store, hash-verified

611
612@array_function_dispatch(_column_stack_dispatcher)
613def column_stack(tup):
614 """
615 Stack 1-D arrays as columns into a 2-D array.
616
617 Take a sequence of 1-D arrays and stack them as columns
618 to make a single 2-D array. 2-D arrays are stacked as-is,
619 just like with `hstack`. 1-D arrays are turned into 2-D columns
620 first.
621
622 Parameters
623 ----------
624 tup : sequence of 1-D or 2-D arrays.
625 Arrays to stack. All of them must have the same first dimension.
626
627 Returns
628 -------
629 stacked : 2-D array
630 The array formed by stacking the given arrays.
631
632 See Also
633 --------
634 stack, hstack, vstack, concatenate
635
636 Examples
637 --------
638 >>> a = np.array((1,2,3))
639 >>> b = np.array((2,3,4))
640 >>> np.column_stack((a,b))
641 array([[1, 2],
642 [2, 3],
643 [3, 4]])
644
645 """
646 arrays = []
647 for v in tup:
648 arr = asanyarray(v)
649 if arr.ndim < 2:
650 arr = array(arr, copy=False, subok=True, ndmin=2).T
651 arrays.append(arr)
652 return _nx.concatenate(arrays, 1)
653
654
655def _dstack_dispatcher(tup):

Callers 1

test_generatorMethod · 0.90

Calls 2

asanyarrayFunction · 0.85
arrayFunction · 0.50

Tested by 1

test_generatorMethod · 0.72