Skip to content

Latest commit

 

History

History
68 lines (47 loc) · 1.05 KB

82ag.md

File metadata and controls

68 lines (47 loc) · 1.05 KB

lang.py.module.numpy.concatenate

Array concatenation capabilities of numpy

Synopsis

  np.concatenate(<tuple-arrays>[, <axis>])

Overview

You can concatenate arrays together with the concatenate() function

Cookbook

Concatenate arrays

  • You need to pass the arrays in concatenating order as a tuple
  • If you pass axis=None it will flatten the arrays
  a = np.array([
      [4, 8],
      [6, 1]
  ])

  b = np.array([
      [3, 5],
      [7, 2],
  ])

  np.concatenate((a, b))

# Out:
  array([[4, 8],
         [6, 1],
         [3, 5],
         [7, 2]])

  np.concatenate((a, b), axis=None)

# Out:
  array([4, 8, 6, 1, 3, 5, 7, 2])

Horizontal and vertical concatenation shortcut

You can use this concatenation api shortcuts:

  • hstack(): Concatenate horizontally
  • vstack(): Concatenate vertically
  np.hstack((a, b))

#  Out:
  array([[4, 8, 3, 5],
         [6, 1, 7, 2]])

  np.vstack((b, a))

# Out:
  array([[3, 5],
         [7, 2],
         [4, 8],
         [6, 1]])