Skip to content

Instantly share code, notes, and snippets.

@myazdani
myazdani / glove-embeddings-load.py
Created March 31, 2019 18:44
Loading glove embeddings in Pandas DataFrame
import pandas as pd
import csv
glove_df = pd.read_csv("glove.6B.50d.txt.zip", sep=" ", index_col=0, header=None,
quoting=csv.QUOTE_NONE)
"new york" in glove_df.index
vocabs = list(glove_df.index)
# jupyter notebook --NotebookApp.iopub_data_rate_limit=1.0e10
import plotly.graph_objs as go
import plotly.graph_objs as go
import plotly.offline as offline
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
offline.init_notebook_mode()
@myazdani
myazdani / plotly-2d-scatter.ipynb
Created December 20, 2017 20:29
Brain dead implementation of 2d interactive scatter plots with plotly in python for rending in a jupyter notebook
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@myazdani
myazdani / dir_check.py
Created July 6, 2017 00:14
Check if a directory exists and create
import os
directory = "sample_dir"
if not os.path.exists(directory):
os.makedirs(directory)
@myazdani
myazdani / gist:b990558ca0df3ca10f77
Created August 20, 2015 15:50
batch rename images png to jpg
ls *.png | awk '{print("mv "$1" "$1)}' | sed 's/png/jpg/2' | /bin/sh
@myazdani
myazdani / resize_images_batch.py
Created July 20, 2015 21:36
resize images to a base width maintaining aspect ratio given a target directory
import os
from PIL import Image
src_path = "./testing2/"
out_path = "./"
basewidth = 75
image_type = (".jpg", ".png", ".JPG", ".PNG", ".JPEG", ".tif", ".tiff", ".TIFF")
image_paths = []
@myazdani
myazdani / Images_From_CSV_to_dir.py
Last active August 29, 2015 14:22
Copy Image paths specified in a CSV column to a specific directory
import pandas as pd
import os
import shutil
import sys
if len(sys.argv) < 1:
print "provide CSV file argument, followed by target directory argument,",\
" followed by which column to use from csv file (optional)"
elif len(sys.argv) < 4:
in_file = sys.argv[1]
@myazdani
myazdani / copy-files-to-chunks.py
Created April 15, 2015 20:37
copy a list of files to a target directory split into evenly sized chunks
import os
import shutil
src_path = "/Users/myazdaniUCSD/Desktop/hourly_colors/"
num_chunks = 6
target_path = "/Users/myazdaniUCSD/Desktop/some_dir/"
def chunks(l, n):
""" Yield successive n-sized chunks from l.
"""
@myazdani
myazdani / chunks.py
Created April 15, 2015 20:28
chunk a list to even sizes
def chunks(l, n):
""" Yield successive n-sized chunks from l.
"""
for i in xrange(0, len(l), n):
yield l[i:i+n]
@myazdani
myazdani / row-normalization.R
Created March 31, 2015 03:32
apply function to multiple columns in data tale
normalized.probs = function(x) {return(x/sum(x))}
res.H = relevant.images[,normalized.probs(.SD), by = filename.path, .SDcols = paste0("H", c(1:180))]