Skip to content

Instantly share code, notes, and snippets.

@64lines
Created November 6, 2017 18:57
Show Gist options
  • Select an option

  • Save 64lines/fb1d02008f3d227732fd8625316fb83f to your computer and use it in GitHub Desktop.

Select an option

Save 64lines/fb1d02008f3d227732fd8625316fb83f to your computer and use it in GitHub Desktop.
[PYTHON][RESHAPING] - Reshaping Arrays
# 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