In [1]:
你好 Python
In [2]:
test
In [3]:
0
1
2
3
4
5
6
7
8
9
In [4]:

一级标题

二级标题

三级标题

魔法命令

%run

In [5]:
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
File D:\py\Python3\lib\site-packages\IPython\core\magics\execution.py:701, in ExecutionMagics.run(self, parameter_s, runner, file_finder)
    700     fpath = arg_lst[0]
--> 701     filename = file_finder(fpath)
    702 except IndexError as e:

File D:\py\Python3\lib\site-packages\IPython\utils\path.py:90, in get_py_filename(name)
     89         return py_name
---> 90 raise IOError("File `%r` not found." % name)

OSError: File `'./My_Test.py'` not found.

The above exception was the direct cause of the following exception:

Exception                                 Traceback (most recent call last)
Cell In[5], line 1
----> 1 get_ipython().run_line_magic('run', './My_Test.py')

File D:\py\Python3\lib\site-packages\IPython\core\interactiveshell.py:2417, in InteractiveShell.run_line_magic(self, magic_name, line, _stack_depth)
   2415     kwargs['local_ns'] = self.get_local_scope(stack_depth)
   2416 with self.builtin_trap:
-> 2417     result = fn(*args, **kwargs)
   2419 # The code below prevents the output from being displayed
   2420 # when using magics with decodator @output_can_be_silenced
   2421 # when the last Python token in the expression is a ';'.
   2422 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):

File D:\py\Python3\lib\site-packages\IPython\core\magics\execution.py:712, in ExecutionMagics.run(self, parameter_s, runner, file_finder)
    710     if os.name == 'nt' and re.match(r"^'.*'$",fpath):
    711         warn('For Windows, use double quotes to wrap a filename: %run "mypath\\myfile.py"')
--> 712     raise Exception(msg) from e
    713 except TypeError:
    714     if fpath in sys.meta_path:

Exception: File `'./My_Test.py'` not found.

%load

In [ ]:
In [6]:
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[6], line 1
----> 1 my_print('Python好,大家好')

NameError: name 'my_print' is not defined

In [7]:
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[7], line 1
----> 1 from My_Test import my_print
      2 my_print('xixi')

ModuleNotFoundError: No module named 'My_Test'

In [8]:
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
File D:\py\Python3\lib\site-packages\IPython\core\magics\execution.py:701, in ExecutionMagics.run(self, parameter_s, runner, file_finder)
    700     fpath = arg_lst[0]
--> 701     filename = file_finder(fpath)
    702 except IndexError as e:

File D:\py\Python3\lib\site-packages\IPython\utils\path.py:90, in get_py_filename(name)
     89         return py_name
---> 90 raise IOError("File `%r` not found." % name)

OSError: File `'./My_Test.py'` not found.

The above exception was the direct cause of the following exception:

Exception                                 Traceback (most recent call last)
Cell In[8], line 2
      1 # notebook对同一个文件只会导入一次
----> 2 get_ipython().run_line_magic('run', './My_Test.py')

File D:\py\Python3\lib\site-packages\IPython\core\interactiveshell.py:2417, in InteractiveShell.run_line_magic(self, magic_name, line, _stack_depth)
   2415     kwargs['local_ns'] = self.get_local_scope(stack_depth)
   2416 with self.builtin_trap:
-> 2417     result = fn(*args, **kwargs)
   2419 # The code below prevents the output from being displayed
   2420 # when using magics with decodator @output_can_be_silenced
   2421 # when the last Python token in the expression is a ';'.
   2422 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):

File D:\py\Python3\lib\site-packages\IPython\core\magics\execution.py:712, in ExecutionMagics.run(self, parameter_s, runner, file_finder)
    710     if os.name == 'nt' and re.match(r"^'.*'$",fpath):
    711         warn('For Windows, use double quotes to wrap a filename: %run "mypath\\myfile.py"')
--> 712     raise Exception(msg) from e
    713 except TypeError:
    714     if fpath in sys.meta_path:

Exception: File `'./My_Test.py'` not found.

In [9]:
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[9], line 1
----> 1 my_print('Python好,大家好')

NameError: name 'my_print' is not defined

%timeit

In [10]:
288 µs ± 16.5 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
In [11]:
301 ms ± 8.75 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
In [12]:
2.9 µs ± 312 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
In [13]:
In [14]:
346 µs ± 14.1 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)

%time

In [15]:
In [16]:
CPU times: total: 0 ns
Wall time: 0 ns
In [17]:
CPU times: total: 15.6 ms
Wall time: 1 ms
In [18]:
1.18 ms ± 389 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
In [19]:
CPU times: total: 31.2 ms
Wall time: 27 ms
In [20]:
CPU times: total: 0 ns
Wall time: 4 ms
In [21]:
CPU times: total: 0 ns
Wall time: 5 ms
In [22]:
CPU times: total: 0 ns
Wall time: 5 ms

%%html

In [23]:
我成功了

%%js

In [24]:

%%writefile

In [25]:
Writing haha.py

numpy

In [26]:
In [27]:
Out[27]:
numpy.ndarray
In [28]:
Out[28]:
(3,)
In [29]:
In [30]:
Out[30]:
(2, 3)
In [31]:
In [32]:
Out[32]:
array([[[0., 0., 0., 0.],
        [0., 0., 0., 0.],
        [0., 0., 0., 0.],
        [0., 0., 0., 0.],
        [0., 0., 0., 0.]],

       [[0., 0., 0., 0.],
        [0., 0., 0., 0.],
        [0., 0., 0., 0.],
        [0., 0., 0., 0.],
        [0., 0., 0., 0.]],

       [[0., 0., 0., 0.],
        [0., 0., 0., 0.],
        [0., 0., 0., 0.],
        [0., 0., 0., 0.],
        [0., 0., 0., 0.]],

       [[0., 0., 0., 0.],
        [0., 0., 0., 0.],
        [0., 0., 0., 0.],
        [0., 0., 0., 0.],
        [0., 0., 0., 0.]],

       [[0., 0., 0., 0.],
        [0., 0., 0., 0.],
        [0., 0., 0., 0.],
        [0., 0., 0., 0.],
        [0., 0., 0., 0.]]])
In [33]:
In [34]:
Out[34]:
array([[ 1,  2,  3,  4],
       [ 5,  6,  7,  8],
       [ 9, 10, 11, 12]])
In [35]:
In [36]:
Out[36]:
array([[2, 3],
       [6, 7]])
In [37]:
In [38]:
Out[38]:
array([[ 6.,  8.],
       [10., 12.]])
In [40]:
Out[40]:
array([[ 6.,  8.],
       [10., 12.]])
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]: