Skip to content

Instantly share code, notes, and snippets.

@mick001
Created August 12, 2018 22:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save mick001/e22582b1d67e02396dcbd199d60d117e to your computer and use it in GitHub Desktop.
Save mick001/e22582b1d67e02396dcbd199d60d117e to your computer and use it in GitHub Desktop.
Download Olivetti faces dataset in Python
# Imports
from sklearn.datasets import fetch_olivetti_faces
import numpy as np
# Download Olivetti faces dataset
olivetti = fetch_olivetti_faces()
x = olivetti.images
y = olivetti.target
# Print info on shapes and reshape where necessary
print("Original x shape:", x.shape)
X = x.reshape((400, 4096))
print("New x shape:", X.shape)
print("y shape", y.shape)
# Save the numpy arrays
np.savetxt("C://olivetti_X.csv", X, delimiter = ",")
np.savetxt("C://olivetti_y.csv", y, delimiter = ",", fmt = '%d')
print("\nDownloading and reshaping done!")
################################################################################
# OUTPUT
################################################################################
#
# Original x shape: (400, 64, 64)
# New x shape: (400, 4096)
# y shape (400,)
#
# Downloading and reshaping done!
@wh0028
Copy link

wh0028 commented Sep 17, 2020

thank you!

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