This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::fs; | |
use std::path::{Path, PathBuf}; | |
pub struct FileNameIterator { | |
directory: PathBuf, | |
entries: Option<fs::ReadDir>, | |
extension: Option<String>, | |
} | |
impl FileNameIterator { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |