{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "ILjn80FamW0K" }, "source": [ "# How to use Colaboratory.\n", "\n", "* [Notebook](https://colab.research.google.com/drive/1RBD7P6XNLvuQvhBLq8sjJxv3Ne553qsY) of this section (open in a separate tab)\n", "\n", "* [Video](https://www.youtube.com/watch?v=h-otOP2hyHM) of this section (17 minutes)" ] }, { "cell_type": "markdown", "metadata": { "id": "5P2TjuPEmW0K" }, "source": [ "Google Coraboratory is a service for using IPython Notebook (Jupyther) online. The entire page, saved with the .ipnyb extension, is called the Notebook, which consists of cells for writing program code and cells for writing text. The cell with the code can be executed by pressing Ctrl + Enter or Shift + Enter." ] }, { "cell_type": "markdown", "source": [ "## To start using" ], "metadata": { "id": "DGApe9mcmW0L" } }, { "cell_type": "markdown", "source": [ "### Using Google Colaboratory:\n", "\n", "- If you have a Google account, you can use the same environment as Jupyter Notebook without installing anything new on your PC.\n", "- You can use GPU for free.\n", "- You can use the GPU for free, but only for up to 12 hours in a row. If you don't access for a while, the connection will be disconnected and initialized.\n" ], "metadata": { "id": "2gnHH6i2mW0L" } }, { "cell_type": "markdown", "source": [ "### Create a new notebook:\n", "- From the \"Welcome to Collaboratory\" page (search for \"Welcome to Collaboratory\"), \"Create a new notebook\".\n", "- Or, in Google Drive, click \"New\" -> \"Other\" -> \"Google Colaboratory\" (for the first time, click \"Add App\" -> \"Search for Colaboratory\" -> \"Install\" here).\n", "- The created notebook is usually saved in the \"Colab Notebooks\" folder of Google Drive.\n" ], "metadata": { "id": "FL-ECXOAmW0L" } }, { "cell_type": "markdown", "source": [ "### How to open an existing notebook:\n", "- Upload the notebook (.ipynb file) to Google Drive and double-click on it (the first time you do this, go to \"Add App\" here -> \"Colaboratory by Search\" -> \"Install\")\n", "- If you get \"Cannot preview\" above, select \"Open with Google Colaboratory\" at the top." ], "metadata": { "id": "N-8KT4wpmW0L" } }, { "cell_type": "markdown", "source": [ "### How to use the notebook\n", "- There are two types of cells, one for code and one for text.\n", "- After writing a command in the text cell for code, click on the ▶ mark, or press Ctrl + Enter or Shift + Enter to execute the command in the cell.\n", "- Cells for text are marked down and can be used with TeX.\n", "- Comment out the code with the `#' mark` `# Use this way`.\n", "- The runtime can be restarted or disconnected from the \"Runtime\" button at the top.\n", "- Restarting the runtime initializes variables and so on. When the runtime is restarted, variables are initialized, etc. When the connection is disconnected, everything is completely initialized except for code and text.\n", "- Files can be viewed from the folder symbol on the left side of the screen.\n", "- The home directory is /content/.\n" ], "metadata": { "id": "AvZOUShdmW0L" } }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "outputId": "80f8a8fb-0857-49dc-b436-650fef398e15", "id": "Og2JVL5kmW0L" }, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1+1" ] }, { "cell_type": "markdown", "metadata": { "id": "UjCaKLCtmW0M" }, "source": [ "## Executing Shell commands in Coraboratory\n", "\n", "You can also execute shell commands (in Lynux) from Notebook.\n", "\n", "For example, the following cell shows the files and directories in the directory.\n", "The leading ! at the beginning declares that it is a shell command, not python code." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "outputId": "d7d29657-a9a1-42b6-c76e-978ce4c64f25", "id": "kfTzfZQEmW0M" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "sample_data\n" ] } ], "source": [ "!ls" ] }, { "cell_type": "markdown", "metadata": { "id": "gaoIzz7-mW0M" }, "source": [ "## Executing Shell commands in Coraboratory\n", "\n", "You can also execute shell commands (in Lynux) from Notebook.\n", "\n", "For example, the following cell shows the files and directories in the directory.\n", "The leading ! at the beginning declares that it is a shell command, not python code." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "outputId": "2f4a1230-21b7-44d9-b213-4040e68516e5", "id": "2CB1o_JpmW0M" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/content\n" ] } ], "source": [ "%cd /content" ] }, { "cell_type": "markdown", "metadata": { "id": "Rvj5uGrlmW0M" }, "source": [ "## Use your own Google Drive.\n", "\n", "* Click on the folder symbol on the left to bring up the \"Mount Drive\" item, click on it, and the cell below will be added automatically.\n", "* After executing it, a message \"Go to this URL in a browser:\" will appear, click on it.\n", "* An authentication window will then appear, and if you select \"Allow,\" an access key will appear.\n", "* Enter it in the input window, and it will be mounted (imported).\n", "* The mounted directory is `/content/drive/My Drive`.\n", "* The home directory is `/content/` to begin with.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "outputId": "6c3468b7-b89d-4f55-ac9b-3067b69e3820", "id": "E1n7mBG8mW0M" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Mounted at /content/drive\n" ] } ], "source": [ "from google.colab import drive\n", "drive.mount('/content/drive')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "outputId": "63fcfa92-183f-4e69-9337-5199748a180b", "id": "H5fMwk35mW0N" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/content/drive/My Drive\n" ] } ], "source": [ "# Need ' ' because there is a space in the directory name\n", "%cd '/content/drive/My Drive'" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "outputId": "d1141b19-0fa7-4181-9da0-7c6867b42e19", "id": "btbnWH5vmW0N" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "\u001b[0m\u001b[01;34msample_data\u001b[0m/\n" ] } ], "source": [ "# You will see a list of files\n", "%ls ./" ] } ], "metadata": { "colab": { "provenance": [] }, "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.8" } }, "nbformat": 4, "nbformat_minor": 0 }