Array Mechanics in Numpy

import numpy as np

1D Array Mechanics

  • By default, Numpy 1D arrays work like row vectors.
  • The transpose of an 1D array, arr.T, returns the same row vector.
  • If transposing a 1D array, use arr[:,None] to create a column vector.
features = np.array([ 0.49671415, -0.1382643 ,  0.64768854])
features
array([ 0.49671415, -0.1382643 ,  0.64768854])
features.T
array([ 0.49671415, -0.1382643 ,  0.64768854])
features[:, None]
array([[ 0.49671415],
       [-0.1382643 ],
       [ 0.64768854]])

2D Array Mechanics

  • Alternatively, set up the array as a 2D. Then arr.T will return a column vector.
features = np.array([ 0.49671415, -0.1382643 ,  0.64768854], ndmin=2)
features
array([[ 0.49671415, -0.1382643 ,  0.64768854]])
features.T
array([[ 0.49671415],
       [-0.1382643 ],
       [ 0.64768854]])