Skip to content

Instantly share code, notes, and snippets.

View guenter-r's full-sized avatar
🐍
Slytherin!

Guenter Roehrich guenter-r

🐍
Slytherin!
View GitHub Profile
@guenter-r
guenter-r / mount_disk.sh
Created April 5, 2023 06:40
Ubuntu Disk Mounting Essentials
# Check file sizes
sudo du -h --max-depth=1 | sort -hr | head -n 10
df -h
###### MOUNTING
https://learn.microsoft.com/en-us/azure/virtual-machines/linux/attach-disk-portal?tabs=ubuntu
# Mount disk
@guenter-r
guenter-r / start.jl
Created May 27, 2020 11:43
Import data Julia
using CSV
using DataFrames
using Statistics
data = CSV.read("./iris_data.txt",header=false)
## no more head
first(data,5)
# renaming column header
@guenter-r
guenter-r / r-knn.R
Last active May 27, 2020 11:45
Knn-like R
knn <- function(new,df,k){
dist_df <- data.frame()
for (i in 1:nrow(df)){
distance <- 0
# calculate distance
for (j in 1:length(new)){
distance <- distance + (new[j] - df[i,j])^2
}
import bs4
def extract_reuters_news(path_file):
file = open(path_file , 'r').read()
soup = bs4.BeautifulSoup(path_file)
all_bodies = [el.text for el in soup.find_all('body')]
return all_bodies
path = './reuters001.html'
reuters = extract_reuters_news(path)
@guenter-r
guenter-r / eigen_triangle.py
Last active May 1, 2020 15:43
Eigenvalues to calculate triangles
from numpy import linalg
def return_eig_triang(graph):
w,v = linalg.eig(graph)
w,v
no_of_triangles = round(np.sum(w**3) / 6,1)
return no_of_triangles # total triangles in the matrix
@guenter-r
guenter-r / create_coo.py
Created May 1, 2020 12:36
Create a coo matrix (scipy)
# create sparse dataset
connections_list = []
for i in range(31):
connections = np.random.choice(21,2) # obviously, repeated values are likely, let's see whether we get triangles too..
connections_list.append(list(connections))
print(connections_list)
x,y = [],[]
for element in connections_list:
xi = element[0]
yi = element[1]
x.append(xi)
x.append(yi) # make symmetric
y.append(yi)
y.append(xi) # make symmetric
# create sparse dataset
connections_list = []
for i in range(31):
connections = np.random.choice(21,2) # obviously, repeated values are likely, let's see whether we get triangles too..
connections_list.append(list(connections))
print(connections_list)
graph = np.array([
[0,1,1,0,0,0,0,0],
[1,0,1,1,1,0,0,1],
[1,1,0,0,0,0,0,0],
[0,1,0,0,1,0,1,1],
[0,1,0,1,0,1,0,0],
[0,0,0,0,1,0,0,0],
[0,0,0,1,0,0,0,0],
[0,1,0,1,0,0,0,0]
])