Skip to content

Instantly share code, notes, and snippets.

View llctrautmann's full-sized avatar
💭
.

Luca Trautmann llctrautmann

💭
.
View GitHub Profile
@llctrautmann
llctrautmann / execute_in_notebook.py
Last active February 3, 2025 17:13
Make python functions executable in Notebooks
# copy into new notebook and run.
# ../src is my preferred structure difference need to be updated.
import sys
from pathlib import Path
# Define the src directory path
src_path = str(Path("../src").resolve())
# Check if it's already in sys.path
@llctrautmann
llctrautmann / audio_tensor_padding.py
Created July 14, 2023 15:20
audio_tensor_padding
@staticmethod
def pad_trunc(aud, max_ms):
sig, sr = aud
num_rows, sig_len = sig.shape
max_len = sr//1000 * max_ms
if (sig_len > max_len):
# Truncate the signal to the given length
sig = sig[:,:max_len]
import csv
# Specify the file path and name
csv_file = '../data/AudioMNIST_Indicies/dummy_labels.csv'
# Specify the number of rows
num_rows = 2997 # change into necessary number of rows
# Open the CSV file in write mode
with open(csv_file, 'w', newline='') as file:
@llctrautmann
llctrautmann / Count_files_in_folder.py
Created July 14, 2023 14:34
Count_files_in_folder
import os
import glob
def count_files(folder_path):
file_list = glob.glob(os.path.join(folder_path, '*'))
return len(file_list)
# Specify the folder path you want to check
folder_path = '../data/AudioMNIST'
@llctrautmann
llctrautmann / sorting_lists_of_lists.py
Created June 7, 2023 09:17
Sort list of lists by item in the inner list
from operator import itemgetter
data = [
5,
"Harry",
37.21,
"Berry",
37.21,
"Tina",
37.2,
@llctrautmann
llctrautmann / lists_collapse.py
Last active June 7, 2023 08:26
Collapse list of lists
out = [x for sublist in out for x in sublist]
Character Description Example Pattern Code Example Match
\d A digit file_\d\d file_25
\D A non digit \D\D\D ABC
\w Alphanumeric \w-\w\w\w A-b_1
\W Non-alphanumeric \W\W\W\W !*+)
\s White space a\sb\sc a b c
\S Non-whitespace \S\S\S\S This