卸载广联达bim算量神器指标神器对算量有没有影响

当前位置: >
Jupyter Notebook的27个窍门,技巧和快捷键 10:06:42&|&编辑:hely&|&查看:&|&评论:
Jupyther notebook ,也就是一般说的 Ipython notebook,是一个可以把代码、图像、注释、公式和作图集于一处,从而实现可读性分析的一种灵活的工具。
10.Jupyter Magic-%who:列出所有的全局变量
不加任何参数, %who 命令可以列出所有的全局变量。加上参数 str 将只列出字符串型的全局变量。
In [1]: one = &for the money&
two = &for the show&
three = &to get ready now go cat go&
one three two
11.Jupyter Magic-计时
有两种用于计时的jupyter magic命令: %%time 和 %timeit.当你有一些很耗时的代码,想要查清楚问题出在哪时,这两个命令非常给力。
仔细体会下我的描述哦。
%%time 会告诉你cell内代码的单次运行时间信息。
In [4]: %%time
import time
for _ in range(1000):
time.sleep(0.01)# sleep for 0.01 seconds
CPU times: user 21.5 ms, sys: 14.8 ms, total: 36.3 ms
Wall time: 11.6 s
%%timeit 使用了Python的 timeit 模块,该模块运行某语句100,000次(默认值),然后提供最快的3次的平均值作为结果。
In [3]: import numpy
%timeit numpy.random.normal(size=100)
The slowest run took 7.29 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 5.5 &s per loop
12.Jupyter Magic-writefile and %pycat:导出cell内容/显示外部脚本的内容
使用%%writefile magic可以保存cell的内容到外部文件。 而%pycat功能相反,把外部文件语法高亮显示(以弹出窗方式)。
In [7]: %%writefile pythoncode.py
import numpy
def append_if_not_exists(arr, x):
if x not in arr:
arr.append(x)
def some_useless_slow_function():
arr = list()
for i in range(10000):
x = numpy.random.randint(0, 10000)
append_if_not_exists(arr, x)
Writing pythoncode.py
In [8]: %pycat pythoncode.py
import numpy
def append_if_not_exists(arr, x):
if x not in arr:
arr.append(x)
def some_useless_slow_function():
arr = list()
for i in range(10000):
x = numpy.random.randint(0, 10000)
append_if_not_exists(arr, x)
13.Jupyter Magic-%prun:告诉你程序中每个函数消耗的时间
使用%prun+函数声明会给你一个按顺序排列的表格,显示每个内部函数的耗时情况,每次调用函数的耗时情况,以及累计耗时。
In [47]: %prun some_useless_slow_function()
26324 function calls in 0.556 seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
0.000 0.528 0.000 :2(append_if_not_exists)
0.000 0.022 0.000 {method 'randint' of 'mtrand.RandomState' objects}
1 0.006 0.006 0.556 0.556 :6(some_useless_slow_function)
0.000 0.001 0.000 {method 'append' of 'list' objects}
1 0.000 0.000 0.556 0.556 :1()
1 0.000 0.000 0.556 0.556 {built-in method exec}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
14.Jupyter Magic-用%pdb调试程序
Jupyter 有自己的调试界面使得进入函数内部检查错误成为可能。
Pdb中可使用的命令见
In [ ]: %pdb
def pick_and_take():
picked = numpy.random.randint(0, 1000)
raise NotImplementedError()
pick_and_take()
Automatic pdb calling has been turned ON
---------------------------------------------------------------------------
NotImplementedError Traceback (most recent call last)
5 raise NotImplementedError()
----& 7 pick_and_take()
in pick_and_take()
3 def pick_and_take():
4 picked = numpy.random.randint(0, 1000)
----& 5 raise NotImplementedError()
7 pick_and_take()
NotImplementedError:
& (5)pick_and_take()
3 def pick_and_take():
4 picked = numpy.random.randint(0, 1000)
----& 5 raise NotImplementedError()
7 pick_and_take()
15.末句函数不输出
有时候不让末句的函数输出结果比较方便,比如在作图的时候,此时,只需在该函数末尾加上一个分号即可。
In [4]: %matplotlib inline
from matplotlib import pyplot as plt
import numpy
x = numpy.linspace(0, 1, 1000)**1.5
In [5]: # Here you get the output of the function
plt.hist(x)
(array([ 216., 126., 106., 95., 87., 81., 77., 73., 71., 68.]),
array([ 0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. ]),
In [6]: # By adding a semicolon at the end, the output is suppressed.
plt.hist(x);
16.运行Shell命令
在notebook内部运行shell命令很简单,这样你就可以看到你的工作文件夹里有哪些数据集。
In [7]: !ls *.csv
nba_2016.csv titanic.csv
pixar_movies.csv whitehouse_employees.csv
17.用LaTex写公式
当你在一个Markdown单元格里写LaTex时,它将用MathJax呈现公式:如
$$ P(A \mid B) = \frac{P(B \mid A) , P(A)}{P(B)} $$
18.在notebook内用不同的内核运行代码
如果你想要,其实可以把不同内核的代码结合到一个notebook里运行。
只需在每个单元格的起始,用Jupyter magics调用kernal的名称:
In [6]: %%bash
for i in {1..5}
echo &i is $i&
搜索"raincent"或扫描下面的二维码为什么jupyter notebook老是安装不了?见图...
jupyter 每次安装到一半就出错,失败,怎么破啊?  不多说,直接上干货!
  这是我自定义的Python&的安装目录 (D:\SoftWare\Python\Python36\Scripts)
1、Jupyter Notebook 和 pip
  为了更加方便地写 Python 代码,还需要安装 Jupyter notebook。 利用 pip 安装 Jupyter notebook。  为什么要使用 Jupyter?参考: /question/
 &pip: Python 的包管理工具,安装 Python 的同时已经安装好了。 &Jupyter notebook: 一个交互式笔记本,支持运行 40 多种编程语言。 利用她来写 Python,代码和运行结果都可以保存下载,十分方便。&
2、Jupyter notebook 安装
&  命令行窗口输入: pip install jupyter  切换到 D:\SoftWare\Python\Python36\Scripts目录下,
  当然,若大家是默认安装的话,则在C:\Users\Administrator\AppData\Local\Programs\Python\Python36\Scripts&目录下 。
   或者将该目录添加到&path,就不用切换了。&
  我这里,因为考虑到机器学习深度学习那边,已经安装了Anaconda2和Anaconda3,所以这边的数据分析所用的python3.6.1就不添加到path了。每次去切换到这个目录来,也不麻烦。
Microsoft Windows [版本 <span style="color: #.1.<span style="color: #01]
版权所有 (c) <span style="color: #09 Microsoft Corporation。保留所有权利。
C:\Users\Administrator&cd /d D:\
D:\&cd D:\SoftWare\Python\Python36\Scripts
D:\SoftWare\Python\Python36\Scripts&pip install jupyter
  安装成功。
3、&jupyter notebook的启动  命令行窗口输入:&jupyter notebook
D:\SoftWare\Python\Python36\Scripts&jupyter notebook
[I <span style="color: #:<span style="color: #:<span style="color: #.828 NotebookApp] Serving notebooks from local directory: D:\SoftWare
\Python\Python36\Scripts
[I <span style="color: #:<span style="color: #:<span style="color: #.828 NotebookApp] <span style="color: # active kernels
[I <span style="color: #:<span style="color: #:<span style="color: #.828 NotebookApp] The Jupyter Notebook is running at: http://localhos
t:<span style="color: #88/?token=<span style="color: #f82159edecad826cefc58f5b87b8d1050b0d
[I <span style="color: #:<span style="color: #:<span style="color: #.829 NotebookApp] Use Control-C to stop this server and shut down all
kernels (twice to skip confirmation).
[C <span style="color: #:<span style="color: #:<span style="color: #.833 NotebookApp]
Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
http://localhost:8888/?token=8f82159edecad826cefc58f5b87b8d10
<span style="color: #b0d
[I <span style="color: #:<span style="color: #:<span style="color: #.628 NotebookApp] <span style="color: #2 GET / (::<span style="color: #) <span style="color: #.00ms
[I <span style="color: #:<span style="color: #:<span style="color: #.647 NotebookApp] <span style="color: #2 GET /tree? (::<span style="color: #) <span style="color: #.00ms
[I <span style="color: #:<span style="color: #:<span style="color: #.535 NotebookApp] Accepting one-time-token-authenticated connection f
rom ::<span style="color: #
  同时,默认浏览器会打开 Jupyter notebook 窗口。 说明 Jupyter notebook 安装成功了。
4、配置 Jupyter notebook&
&jupyter notebook --generate-config
  打开“.jupyter”文件夹,可以看到里面有个配置文件。
Microsoft Windows [版本 <span style="color: #.1.<span style="color: #01]
版权所有 (c) <span style="color: #09 Microsoft Corporation。保留所有权利。
C:\Users\Administrator&cd /d D:\
D:\&cd D:\SoftWare\Python\Python36\Scripts
D:\SoftWare\Python\Python36\Scripts&jupyter notebook --generate-config
Writing default config to: C:\Users\Administrator\.jupyter\jupyter_notebook_conf
D:\SoftWare\Python\Python36\Scripts&
  修改jupyter_notebook_config.py配置文件  打开这个配置文件,找到“c.NotebookApp.notebook_dir=……”,把路径改成自己的工作目录。
 比如,这里要变更为
## The directory to use for notebooks and kernels.c.NotebookApp.notebook_dir = 'D:\Code\jupyter-notebook'
,当然,文件夹&jupyter-notebook&需要自己创建好。&
  配置文件修改完成后, 以后在 jupyter notebook 中写的代码等都会保存在自己创建的目录中。
&jupyter notebook的自定义启动(变了)  配置文件修改成后,就可以启动 jupyter notebook 了,命令行窗口中输入 jupyter notebook,  默认浏览器就会打开一个页面
&jupyter notebook的启动  命令行窗口输入:&jupyter notebook
  以前是
D:\SoftWare\Python\Python36\Scripts&jupyter notebook
[I 10:37:02.828 NotebookApp] Serving notebooks from local directory: D:\SoftWare
\Python\Python36\Scripts
[I 10:37:02.828 NotebookApp] 0 active kernels
[I 10:37:02.828 NotebookApp] The Jupyter Notebook is running at: http://localhos
t:8888/?token=8f82159edecad826cefc58f5b87b8d1050b0d
[I 10:37:02.829 NotebookApp] Use Control-C to stop this server and shut down all
kernels (twice to skip confirmation).
[C 10:37:02.833 NotebookApp]
Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
http://localhost:8888/?token=8f82159edecad826cefc58f5b87b8d10
[I 10:37:03.628 NotebookApp] 302 GET / (::1) 1.00ms
[I 10:37:03.647 NotebookApp] 302 GET /tree? (::1) 5.00ms
[I 10:37:05.535 NotebookApp] Accepting one-time-token-authenticated connection f
&  现在是
Microsoft Windows [版本 <span style="color: #.1.<span style="color: #01]
版权所有 (c) <span style="color: #09 Microsoft Corporation。保留所有权利。
C:\Users\Administrator&cd /d D:\
D:\&cd D:\SoftWare\Python\Python36\Scripts
D:\SoftWare\Python\Python36\Scripts&jupyter notebook
[I <span style="color: #:<span style="color: #:<span style="color: #.326 NotebookApp] Serving notebooks from local directory: D:\Code\jup
yter-notebook
[I <span style="color: #:<span style="color: #:<span style="color: #.327 NotebookApp] <span style="color: # active kernels
[I <span style="color: #:<span style="color: #:<span style="color: #.327 NotebookApp] The Jupyter Notebook is running at: http://localhos
t:<span style="color: #88/?token=e520d6b824bd77fe9cc5fdc774
[I <span style="color: #:<span style="color: #:<span style="color: #.328 NotebookApp] Use Control-C to stop this server and shut down all
kernels (twice to skip confirmation).
[C <span style="color: #:<span style="color: #:<span style="color: #.332 NotebookApp]
Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
http://localhost:8888/?token=e520d6b824bd77fe9cc5f
[I <span style="color: #:<span style="color: #:<span style="color: #.532 NotebookApp] Accepting one-time-token-authenticated connection f
rom ::<span style="color: #
&  当然,其实啊,这个玩意非常的简单和方便。关于修改名字、上传等操作,后续关注的我博客。
常见问题及解决方案
如何添加 Path?计算机-右击-单机“属性”&
单机“高级系统设置”
&  单机“环境变量”
  找到系统变量 path,编辑在最后加上 2 个路径:C:\Users\Administrator\AppData\Local\Programs\Python\Python36C:\Users\Administrator\AppData\Local\Programs\Python\Python36\Scripts  说明:以上默认安装路径,每个电脑上是类似的,找到复制这个路径加到 Path 中即可
  我的路径是已经改了,在下面的这篇博客里,可以看到
这是我自定义的Python&的安装目录 (D:\SoftWare\Python\Python36\Scripts)
jupyter notebook 闪退  解决办法:更换默认浏览器。 ,建议用谷歌浏览器或者火狐浏览器
阅读(...) 评论()

我要回帖

更多关于 广联达如何卸载干净 的文章

 

随机推荐