{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Cheetsheet"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## General\n",
    "* **Getting help**: ```help(my_function)```, ```help(my_module.my_function)```, ```help(my_variable.my_method)```\n",
    "\n",
    "\n",
    "* **Import a module**: ```import my_module``` or ```import my_module as mm```\n",
    "\n",
    "\n",
    "* **Import a function from a module**: ```from my_module import my_function```\n",
    "\n",
    "\n",
    "* **Creating a function**:\n",
    "\n",
    "```python\n",
    "def my_function(a, b = 3):\n",
    "    my_output = a * b\n",
    "    return my_output\n",
    "```\n",
    "\n",
    "* **Creating a for loop**: \n",
    "\n",
    "```python\n",
    "for i in my_list:\n",
    "    do something with each i element of my_list\n",
    "    each line does some operation\n",
    "    there can be multiple lines\n",
    "    all lines have to be INDENTED\n",
    "```\n",
    "```python\n",
    "for i in range(10):\n",
    "    do something with i which takes values from 0 to 9\n",
    "```\n",
    "\n",
    "* **Creating an if statement**:\n",
    "\n",
    "```python\n",
    "if a > b:\n",
    "    do something if a > b\n",
    "elif a > c:\n",
    "    if the first condition is unmet, do something if a > c\n",
    "else:\n",
    "    in all other cases do another operation\n",
    "    each bloch can have multiple lines\n",
    "    as in the for loop, the blocks have to be INDENTED\n",
    "```\n",
    "\n",
    "* **Having multiple blocks**:\n",
    "\n",
    "```python\n",
    "for i in my_list:\n",
    "    print(i)\n",
    "    if i > 5:\n",
    "        new_var = i * 2\n",
    "```\n",
    "\n",
    "## Numpy\n",
    "* **Create zeros array**: ```my_array = np.zeros((5,7))```\n",
    "\n",
    "\n",
    "* **Get value at row = 3, column = 4**: ```my_value = my_array[3,4]```\n",
    "\n",
    "\n",
    "* **Get all columns of row = 3**: ```my_array[3,:]```\n",
    "\n",
    "\n",
    "* **Create boolean array by a logical operation**: ```my_boolean_array = my_array > 10```\n",
    "\n",
    "\n",
    "* **Check array size**: ```my_array.shape```\n",
    "\n",
    "\n",
    "* **Get pixel values of image under mask**: ```pixel_values = image[mask]```\n",
    "\n",
    "\n",
    "* **Flatten an array (make it 1D)**: ```array_1D = np.ravel(my_array)```\n",
    "\n",
    "## Matplotlib\n",
    "* **Plot an image**:\n",
    "\n",
    "```python\n",
    "plt.subplots(figsize=(10,10))\n",
    "plt.imshow(my_image)\n",
    "plt.show()\n",
    "```\n",
    "\n",
    "* **Histogram with specific bins**:\n",
    "\n",
    "```python\n",
    "plt.hist(my_data, bins = np.arange(0,1000,1))\n",
    "plt.show()\n",
    "```\n",
    "\n",
    "## Pandas\n",
    "* **Create a Dataframe from list of dictionaries**: ```my_dataframe = pd.DataFrame(my_dictlist)```\n",
    "\n",
    "\n",
    "* **Create a Dataframe from a 2D array with three columns**:\n",
    "\n",
    "```python\n",
    "my_dataframe = pd.DataFrame(my_2Darray, columns=['col1','col2','col3'])\n",
    "```\n",
    "\n",
    "\n",
    "* **Recover a the my_param column for all rows**: ```my_dataframe.my_param``` or ```my_dataframe['my_param']```\n",
    "\n",
    "\n",
    "* **Calculate mean of a column called my_param**: ```my_dataframe.my_param.mean()```\n",
    "\n",
    "\n",
    "* **Calculate statistic for full table**: ```my_dataframe.mean()```\n",
    "\n",
    "## Skimage\n",
    "* **Import an image from your computer**: ```skimage.io.imread('/path/to/your/file.tif')```\n",
    "\n",
    "\n",
    "* **Import an image from the web**: ```skimage.io.imread('http://mysite/my_image.tif')```\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.2"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
