Skip to content

Instantly share code, notes, and snippets.

View BenedictWilkins's full-sized avatar

Benedict Wilkins BenedictWilkins

View GitHub Profile
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 18 10:27:51 2019
Example use of tkinter with python threading.
@author: Benedict Wilkins AI
"""
import tkinter as tk
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 18 10:27:51 2019
Incorrect example use of tkinter with Python threading
@author: Benedict Wilkins AI
"""
import tkinter as tk
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Oct 24 12:55:41 2019
Boiler-plate code for tkinter and Python threading
@author: Benedict Wilkins AI
"""
import tkinter as tk
@BenedictWilkins
BenedictWilkins / Plot Image in 3D
Created October 25, 2019 14:53
Plot an Image in 3D with pyplot
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Oct 24 19:33:19 2019
Plot an image in 3D using pyplot.
Assumes image is grayscale and in HWC format.
@author: Benedict Wilkins
"""
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@BenedictWilkins
BenedictWilkins / siamese-network.ipynb
Last active September 28, 2020 09:12
Train a siamese network on MNIST
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
"""
Computes a one-hot encoding of a multi-dimensional numpy array. Uses numpy advanced indexing...
If anyone has ideas for a more efficient version please let me know!
Example 1:
import numpy as np
x = np.random.randint(0,3,size=(2,2))
y = onehot(x, (2,2,3))
print(x)
@BenedictWilkins
BenedictWilkins / observation_slicing.py
Created October 28, 2020 15:50
OpenAI Gym observation slicing
import numpy as np
import gym
class BoxSlice(gym.spaces.Box):
def __init__(self, box, s_ = np.s_[:,:,:]):
assert isinstance(box, gym.spaces.Box)
self.__box = box
self.__slice = s_
super(BoxSlice, self).__init__(box.low, box.high, dtype=box.dtype)
@BenedictWilkins
BenedictWilkins / filenameiterator.rs
Created July 18, 2023 09:54
filenameiterator.rs
use std::fs;
use std::path::{Path, PathBuf};
pub struct FileNameIterator {
directory: PathBuf,
entries: Option<fs::ReadDir>,
extension: Option<String>,
}
impl FileNameIterator {
@BenedictWilkins
BenedictWilkins / matplotlib axis aligned rectangle hatch
Created November 20, 2023 10:55
Implementation of hatching for an axis aligned rectangle.
def line_intersection(line1, line2):
"""
Find the intersection of two lines.
Each line is defined by a pair of points (x1, y1) and (x2, y2).
"""
x1, y1, x2, y2 = line1
x3, y3, x4, y4 = line2
denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4)
if denominator == 0: