Skip to content

Instantly share code, notes, and snippets.

nafeesb /
Last active Jun 11, 2021
Matplotlib recipes

Load image with imageio

import imageio
import matplotlib.pyplot as plt
img = imageio.imread('file.jpg')

Load image with PIL

nafeesb /
Created Mar 3, 2018
Maya load plugin in a standalone context
# good for testing frameworks
import maya.standalone
from maya import cmds
#Uploading the Dataset
from google.colab import files
uploaded = files.upload()
#Save uploaded file on the Virtual Machine's
#Thanks to user3800642 from StackOverflow
with open("breast_cancer.csv", 'w') as f:
# Restart the VM
!kill -9 -1
## Mount a google drive
# install prereqs
!apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!apt-get update -qq 2>&1 > /dev/null
!apt-get -y install -qq google-drive-ocamlfuse fuse
from google.colab import auth
nafeesb / vex_avg_nbor_dist.cpp
Created Jun 8, 2018
Average distance to neighbor points
View vex_avg_nbor_dist.cpp
/// Average max distance
float maxdistance = 15;
int maxpoints = 5;
int closept[] = pcfind_radius(0, "P", "pscale", 1.0, @P, maxdistance, maxpoints);
f@dist = 0;
foreach (int opt; closept) {
vector npos = point(0, "P", opt);
nafeesb /
Last active Aug 14, 2019
Pytorch snippets

Free GPU memory

del object_using_gpu

Tensor memory use

sz = a.element_size() * a.nelement()
sz_gb = sz >> 30
nafeesb / orthonormal_basis.cs
Created Nov 16, 2018
Duff's branchless onb
View orthonormal_basis.cs
void branchlessONB( Vector3 N, ref Vector3 A, ref Vector3 B)
float sign = N.z >= 0.0f ? 1.0f : -1.0f;
float a = 1.0f / (sign + N.z);
float b = N.x * N.y * a;
A.Set(1.0f + sign * N.x * N.x * a, sign * b, -sign * N.x);
B.Set(b, sign + N.y * N.y * a, -N.y);
nafeesb /
Last active Jan 9, 2019
pytorch 1d regression
import numpy as np
import torch
from torch import nn
from itertools import count
import time
# make some data
N = 100
nafeesb /
Created Nov 21, 2018
Installing OpenAI Gym in Windows

Anaconda Configuration

conda create -n tensorflow tensorflow-gpu pip python=3.6
conda install ipython matplotlib cython mkl_random mkl mkl-devel swig

Install OpenAI Gym

Install from source:

pip install -e .
nafeesb /
Last active Jul 28, 2021
Numpy Idioms

Ouput Zero for divide by zero

length_err_pct = np.divide( pred_length, true_length, out=np.zeros_like(pred_length), where=true_length!=0)

Random subset of indices

sel = np.random.choice(testX.shape[0], samples, replace=False)

Save formatting