2021 – Advent of code – Day 2

Part 1 Today the puzzle got a bit trickier than Day 1. The submarine seems to already have a planned course (your puzzle input). You should probably figure out where it’s going. For example: forward 5 down 5 forward 8 up 3 down 8 forward 2 Your horizontal position and depth both start at 0.…

Argparse

Primer: Arguments vs Parameters I’m sometimes confused. Is it an argument or a parameter? So here it goes: A parameter is a variable in a function definition. When a function is called, the arguments are the data you pass into the function’s parameters. The same goes for a program: A program has parameters, you call…

Pandas Cheat Sheet

If you are new to Pandas feel free to read Introduction to Pandas I’ve assembled some pandas code snippets Reading Data Reading CSV import pandas as pd # read from csv df = pd.read_csv(“path_to_file”) Can also be textfiles. file suffix is ignored

Intro to OpenCV with Python

Installation To work with OpenCV from python, you need to install it first: pip install opencv-python Reading Images from file After we import cv2 we can directly work with images like so: import cv2 img = cv2.imread(“doc_brown.png”) For showing the image, it is recommended to use matplotlib import matplotlib.pyplot as plt img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)…

Linear Algebra with numpy

Numpy is a package for scientific computing in Python. It is blazing fast due to its implementation in C. It is often used together with pandas, matplotlib and Jupyter notebooks. Often these packages are referred to as the datascience stack. Installation You can install numpy via pip pip install numpy Basic Usage In the datascience…

pip optional dependencies

Sometimes you want to make your python package usable for different situations, e.g. flask or bottle or django. If You want to minimize dependencies You can use an optional dependency in setup.py: extras_require={ ‘flask’: [‘Flask>=0.8’, ‘blinker>=1.1’] } Now you can install the library with: pip install raven[flask]