Skip to content

Instantly share code, notes, and snippets.

@arshednabeel
Last active November 29, 2017 20:29
Show Gist options
  • Save arshednabeel/c1811d02a8c64e7874f0310292c47c37 to your computer and use it in GitHub Desktop.
Save arshednabeel/c1811d02a8c64e7874f0310292c47c37 to your computer and use it in GitHub Desktop.
NumPy Noob Trick: Flatten out all except the last dimension of an ndarray.

The following command flattens out all except the last dimension of an n-d array; useful, for example, to create a feature vector. W_flat = W.reshape((-1,W.shape[-1]))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment