Last active
January 24, 2019 20:12
-
-
Save christinebuckler/243b05cd86e8f7b00786fa002b9a5586 to your computer and use it in GitHub Desktop.
np 2d array (n,1) to 1d (n,) array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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