Skip to content

Instantly share code, notes, and snippets.

@christinebuckler
Last active January 24, 2019 20:12
Show Gist options
  • Save christinebuckler/243b05cd86e8f7b00786fa002b9a5586 to your computer and use it in GitHub Desktop.
Save christinebuckler/243b05cd86e8f7b00786fa002b9a5586 to your computer and use it in GitHub Desktop.
np 2d array (n,1) to 1d (n,) array
import numpy
array_2d = np.array([1, 2, 3]).reshape(-1,1)
array_2d.shape # (3,1)
array_1d = array_2d.flatten()
array_1d.shape # (3,)
# and from 1d back to 2d...
a = pd.Series([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]], dtype=object).values
a.shape # (4,)
b = np.vstack(a)
b.shape # (4,3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment