The environment

  • 10 64 – bit Windows
  • jupyter notebook

Executing shell Commands

When you’re happily typing code in the Jupyter Notebook, do you exit to execute shell commands?

You don’t have to. You can run the shell command in the notebook, just put it in front of the command. No.

View shortcut Keys

As we all know the importance of shortcut keys, mastering shortcuts can greatly improve our work efficiency. In Jupyter Notebook, we can easily check shortcuts

  • Press theEscKey to enter the command mode (command mode)
  • Press thehkey

Magic command

In Jupyter Notebook, there are a lot of magic commands, which are very useful to make your work easier and more efficient

Use %lsmagic to see all magic commands

For some unfamiliar magic commands, you can select it, press Shift + TAB to see help information, very nice

Count the cell running time

The %%time is used to get the elapsed time of code execution, which is useful for statistical analysis and performance tuning

Multi-line editing (multi-cursor support)

Multiple lines of code can be edited at the same time, absolutely save time and effort. Press Alt and use the left mouse button to select

Of course, naming variables like this is not recommended, as it will get hammered by the leader

Hide some output information

Added at the end of the statement; , you can remove some of the annoying output information. For example, when we draw with Matplotlib

For the most part, the information in the red box is not needed, so you can hide it by adding a comma at the end of the PLT code

plt.scatter(x, y);
Copy the code

View the module help information

Use? Canadian method name can be very convenient to view help documents

Setting environment variables

In machine learning/deep learning, we often encounter the use of environment variables, in the Jupyter notebook also can set and modify environment variables, using %env

%env THIS_IS_ENV_EXAMPLE "xugaoxiang.com"
Copy the code

Here, THIS_IS_ENV_EXAMPLE is the environment variable, and its value is the string xugaoxiang.com

Saves cell contents to files and displays file contents in cells

Use %% Writefile to save the contents of a cell to an external file

Use % PyCat to display the contents of an external file as a pop-up

Code debugging

Using % PDB, you can debug in the Notebook

Automatic pdb calling has been turned ON
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-10-869a75f9e69b> in <module>
      4     raise NotImplementedError()
      5 
----> 6 pick_and_take()

<ipython-input-10-869a75f9e69b> in pick_and_take()
      2 def pick_and_take():
      3     picked = np.random.randint(0, 1000)
----> 4     raise NotImplementedError()
      5 
      6 pick_and_take()

NotImplementedError: 

> <ipython-input-10-869a75f9e69b>(4)pick_and_take()
      2 def pick_and_take():
      3     picked = np.random.randint(0, 1000)
----> 4     raise NotImplementedError()
      5 
      6 pick_and_take()

ipdb> 

Copy the code

As you can see, in the ipdb > prompt after can input the corresponding instruction, concrete can reference links docs.python.org/3.8/library…

The resources

  • Xugaoxiang.com/2020/10/28/…
  • Xugaoxiang.com/2020/10/29/…