Created
November 6, 2017 18:57
-
-
Save 64lines/fb1d02008f3d227732fd8625316fb83f to your computer and use it in GitHub Desktop.
[PYTHON][RESHAPING] - Reshaping Arrays
This file contains hidden or 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 and pandas | |
| import numpy as np | |
| import pandas as pd | |
| # Read the CSV file into a DataFrame: df | |
| df = pd.read_csv('gapminder.csv') | |
| # Create arrays for features and target variable | |
| y = df['life'].values | |
| X = df['fertility'].values | |
| # Print the dimensions of X and y before reshaping | |
| print("Dimensions of y before reshaping: {}".format(y.shape)) | |
| print("Dimensions of X before reshaping: {}".format(X.shape)) | |
| # Reshape X and y | |
| y = y.reshape(-1, 1) | |
| X = X.reshape(-1, 1) | |
| # Print the dimensions of X and y after reshaping | |
| print("Dimensions of y after reshaping: {}".format(y.shape)) | |
| print("Dimensions of X after reshaping: {}".format(X.shape)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment