A simple example of using Jupyter Notebook in Anaconda3

Jupyter Notebook (formerly known as IPython Notebook) is an interactive notebook that supports over forty programming languages. It appeared to make it convenient for scientific researchers to generate PDF or web page format of their own text, code and operation results to communicate with everyone at any time.

In programming language, Jupyter Notebook is a web-based application for interactive computing. It can be applied to the whole process of computing: development, documentation, running code and displaying results. In short, Jupyter Notebook is a program that opens in the form of a web page. You can directly write and run code on the web page, and the running result of the code will also be displayed directly under the code block. If you need to write an instruction document during the programming process, you can write it directly on the same page, which is convenient for timely explanation and explanation.

Start Jupyter Notebook in Anaconda3-2022.10

Click the "Launch" button in the Jupyter Notebook of the Navigator interface of Anaconda3-2022.10,

Anaconda Navigator will start the browser, and the display interface is as follows:

 

The URL in the browser is: http://localhost:8889/tree 

Simple use of Jupyter Notebook

Click the "New" drop-down list box in the browser interface, and then click "Python3 (ipykernel)".

 

After clicking, enter the page http://localhost:8889/notebooks/Untitled.ipynb?kernel_name=python3 

 

Among them, the part inside the red rectangle is called a cell (Cell); the whole page is called a Notebook, and each Notebook consists of multiple cells.

Each menu item is shown in the figure below:

Beginning with "In[ ]" indicates that this is a code unit . In the code cell, code can be entered and executed. For example, enter the code:

a=1

b=2

print(a+b)

Then press the " Shift+Enter " key combination or click the " Run " button as shown in the figure below, the code will be run and the result will be displayed.

Advanced usage of Markdown cells in Jupyter Notebook

Markdown cells can accept HTML codes, so that richer styles can be implemented in the cells, such as adding pictures, etc.

Use the Google Chrome browser to copy the address of the image, as shown in the figure below:

The image address (URL) obtained is: https://alifei00.cfp.cn/static/home/h2_5.png?x-oss-process=image/format,webp 

Then change the cell type to "Markdown" in Jupyter Notebook:

Then enter the following html code:

<img src="https://alifei00.cfp.cn/static/home/h2_5.png?x-oss-process=image/format,webp" style="width:200px;height:200px;float:left">

 Running the code in the above cell results in a picture, as shown below:

In addition, Markdown cells also support LaTex syntax . For example: Enter and execute code in a Markdown cell:    $$\int_0 ^ {+\infty}x^2dx$$

 

will get the LaTex equation:

 

Export function of Jupyter Notebook

Jupyter Notebook has a powerful export function, which can export Notebook to various formats, such as html, Markdown, ReST, PDF (via LaTex), Raw Python, etc.

In the File->Download as menu, as shown below:

Related references:

  1. The Jupyter Notebook. The Jupyter Notebook — Jupyter Notebook 6.5.2 documentation 
  2. Jupyter Notebook introduction, installation and usage tutorial. Jupyter Notebook introduction, installation and usage tutorial-Know 
  3. The Application of Python in Machine Learning. Yu Benguo, Sun Yulin. China Water Conservancy and Hydropower Press [Beijing], first edition in June 2019.

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/Alexabc3000/article/details/127603793