﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-杰-随笔分类-Python</title><link>http://www.cppblog.com/guijie/category/21368.html</link><description>杰哥好,哈哈!</description><language>zh-cn</language><lastBuildDate>Sat, 05 Sep 2020 14:27:37 GMT</lastBuildDate><pubDate>Sat, 05 Sep 2020 14:27:37 GMT</pubDate><ttl>60</ttl><item><title>[zz] Python3中print()函数输出多个变量</title><link>http://www.cppblog.com/guijie/archive/2020/09/05/217438.html</link><dc:creator>杰哥</dc:creator><author>杰哥</author><pubDate>Sat, 05 Sep 2020 00:44:00 GMT</pubDate><guid>http://www.cppblog.com/guijie/archive/2020/09/05/217438.html</guid><wfw:comment>http://www.cppblog.com/guijie/comments/217438.html</wfw:comment><comments>http://www.cppblog.com/guijie/archive/2020/09/05/217438.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guijie/comments/commentRss/217438.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guijie/services/trackbacks/217438.html</trackback:ping><description><![CDATA[<h3>第一种方法：&nbsp; &nbsp; &nbsp;print("变量1", file_name, "变量2", new_name)</h3><pre name="code" style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 24px; padding: 8px; position: relative; font-family: Consolas, Inconsolata, Courier, monospace; white-space: pre-wrap; overflow-wrap: break-word; overflow-x: auto; line-height: 22px; background-color: #ffffff;"><code hljs"="" style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 8px; font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; display: block; overflow-x: auto; color: #abb2bf; background: #282c34; border-radius: 4px; line-height: 22px; white-space: pre; overflow-wrap: break-word; tab-size: 4;">print(<span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; color: #98c379; overflow-wrap: break-word;">"变量1"</span>, file_name, <span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; color: #98c379; overflow-wrap: break-word;">"变量2"</span>, new_name) </code></pre><h3><a name="t1" style="box-sizing: border-box; outline: none; margin: 0px; padding: 0px; font-weight: normal; cursor: pointer; color: rgb(78, 161, 219); overflow-wrap: break-word;"></a><a name="t1" style="box-sizing: border-box; outline: none; margin: 0px; padding: 0px; font-weight: normal; cursor: pointer; color: rgb(78, 161, 219); overflow-wrap: break-word;"></a>第二种方法：&nbsp; &nbsp; &nbsp;print("变量1：%s 变量2：%s" % (file_name, new_name))</h3><pre name="code" style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 24px; padding: 8px; position: relative; font-family: Consolas, Inconsolata, Courier, monospace; white-space: pre-wrap; overflow-wrap: break-word; overflow-x: auto; line-height: 22px; background-color: #ffffff;"><code hljs"="" style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 8px; font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; display: block; overflow-x: auto; color: #abb2bf; background: #282c34; border-radius: 4px; line-height: 22px; white-space: pre; overflow-wrap: break-word; tab-size: 4;">print(<span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; color: #98c379; overflow-wrap: break-word;">"变量1：%s 变量2：%s"</span> % (file_name, new_name)) </code></pre><h3><a name="t2" style="box-sizing: border-box; outline: none; margin: 0px; padding: 0px; font-weight: normal; cursor: pointer; color: rgb(78, 161, 219); overflow-wrap: break-word;"></a><a name="t2" style="box-sizing: border-box; outline: none; margin: 0px; padding: 0px; font-weight: normal; cursor: pointer; color: rgb(78, 161, 219); overflow-wrap: break-word;"></a>第三种方法：.format()&nbsp;&nbsp;</h3><p style="box-sizing: border-box; outline: 0px; margin: 0px 0px 16px; padding: 0px; font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; font-size: 18px; color: #4d4d4d; line-height: 26px; overflow-x: auto; overflow-wrap: break-word; background-color: #ffffff;">print('变量1：{0} 变量2：{1}'.format(file_name, new_name))</p><pre name="code" style="box-sizing: border-box; outline: 0px; margin-top: 0px; margin-bottom: 24px; padding: 8px; position: relative; font-family: Consolas, Inconsolata, Courier, monospace; white-space: pre-wrap; overflow-wrap: break-word; overflow-x: auto; line-height: 22px; background-color: #ffffff;"><code hljs"="" style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 8px; font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; display: block; overflow-x: auto; color: #abb2bf; background: #282c34; border-radius: 4px; line-height: 22px; white-space: pre; overflow-wrap: break-word; tab-size: 4;"><ol style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; list-style: none; font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; border-collapse: collapse; font-size: 18px; overflow: hidden; overflow-wrap: break-word;"><li style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; list-style: none; overflow-wrap: break-word; height: 22px;"><div style="box-sizing: border-box; outline: 0px; margin: 0px; overflow-wrap: break-word; font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-size: 14px; float: left; height: 22px; width: 24px; border-right: 1px solid #c5c5c5;"><div hljs-ln-n"="" data-line-number="1" style="box-sizing: border-box; outline: 0px; margin: 0px; padding-right: 8px; text-align: right; overflow-wrap: normal;"></div></div><div style="box-sizing: border-box; outline: 0px; margin: 0px 0px 0px 8px; overflow-wrap: break-word; font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-size: 14px; float: left; height: 22px;"><div style="box-sizing: border-box; outline: 0px; margin: 0px; overflow-wrap: break-word;">print(<span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; color: #98c379; overflow-wrap: break-word;">'变量1：{0} 变量2：{1}'</span>.format(file_name, new_name))</div></div></li><li style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; list-style: none; overflow-wrap: break-word; height: 22px;"><div style="box-sizing: border-box; outline: 0px; margin: 0px; overflow-wrap: break-word; font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-size: 14px; float: left; height: 22px; width: 24px; border-right: 1px solid #c5c5c5;"><div hljs-ln-n"="" data-line-number="2" style="box-sizing: border-box; outline: 0px; margin: 0px; padding-right: 8px; text-align: right; overflow-wrap: normal;"></div></div><div style="box-sizing: border-box; outline: 0px; margin: 0px 0px 0px 8px; overflow-wrap: break-word; font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif; font-size: 14px; float: left; height: 22px;"><div style="box-sizing: border-box; outline: 0px; margin: 0px; overflow-wrap: break-word;"><span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; color: #5c6370; font-style: italic; overflow-wrap: break-word;"># 需要注意的是，python是从0开始计数，所以第一个{}里要从0开始，依次1、2&#8230;</span></div></div></li><li style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; list-style: none; overflow-wrap: break-word; height: 22px;"><div><span style="box-sizing: border-box; outline: 0px; margin: 0px; padding: 0px; color: #5c6370; font-style: italic; overflow-wrap: break-word;"><br /></span></div></li></ol></code></pre>Reference:<br /><div>https://blog.csdn.net/zhangvalue/article/details/103841029</div><img src ="http://www.cppblog.com/guijie/aggbug/217438.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guijie/" target="_blank">杰哥</a> 2020-09-05 08:44 <a href="http://www.cppblog.com/guijie/archive/2020/09/05/217438.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[zz] 3 个相见恨晚的 Google Colaboratory 奇技</title><link>http://www.cppblog.com/guijie/archive/2019/02/13/216240.html</link><dc:creator>杰哥</dc:creator><author>杰哥</author><pubDate>Wed, 13 Feb 2019 15:56:00 GMT</pubDate><guid>http://www.cppblog.com/guijie/archive/2019/02/13/216240.html</guid><wfw:comment>http://www.cppblog.com/guijie/comments/216240.html</wfw:comment><comments>http://www.cppblog.com/guijie/archive/2019/02/13/216240.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guijie/comments/commentRss/216240.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guijie/services/trackbacks/216240.html</trackback:ping><description><![CDATA[<p><span style="color: #b2b2b2;">原文出处：</span></p><p><span style="color: #b2b2b2;">https://www.kdnuggets.com/2018/02/essential-google-colaboratory-tips-tricks.html</span></p><p><span style="color: #534e4e; font-size: 15px;"><br /></span></p><p><span style="color: #534e4e; font-size: 15px;">试想一下，如果有个免费的在线云端平台，既可以不用安装 TensorFlow 直接使用，又可以实现 GPU 加速训练，那该是多好的一件事情。你没听错，这种好事确实存在！今天我就重磅介绍一个谷歌推出的免费的云端工具：Colaboratory。</span></p><p><span style="color: #534e4e; font-size: 15px;"><br /></span></p><p><span style="color: #534e4e; font-size: 15px;">Colaboratory 是一个 Google 研究项目，旨在帮助传播机器学习培训和研究成果。</span><span style="color: red; font-size: 15px;">它是一个 Jupyter 笔记本环境</span><span style="color: #534e4e; font-size: 15px;">，不需要进行任何设置就可以使用，并且完全在云端运行。Colaboratory 笔记本存储在 Google 云端硬盘中，并且可以共享，就如同您使用 Google 文档或表格一样。Colaboratory 可免费使用。</span></p><p><span style="color: #534e4e; font-size: 15px;"><br /></span></p><p><span style="color: #534e4e; font-size: 15px;">也就是说，Colaboratory 存储在 Google 云端硬盘中，我们可以在 Google 云端硬盘里直接编写 Jupyter Notebook，在线使用深度学习框架 TensorFlow 并训练我们的神经网络了。超炫！</span></p><p><span style="color: #534e4e; font-size: 15px;"><br /></span></p><p><img style="width: 614px !important; height: auto !important; visibility: visible !important;" src="https://mmbiz.qpic.cn/mmbiz_jpg/hflWRBRSEZ4HGq3Cc45aXDDNG4icg1zoYt3fVHialOuk2BAk5TSXPDJsXMAAn4fsBk4CcsgEhgW7AXBaujPjBIBw/640?wx_fmt=jpeg&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" crossorigin="anonymous" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/hflWRBRSEZ4HGq3Cc45aXDDNG4icg1zoYt3fVHialOuk2BAk5TSXPDJsXMAAn4fsBk4CcsgEhgW7AXBaujPjBIBw/640?wx_fmt=jpeg" data-w="614" data-type="jpeg" data-s="300,640" data-ratio="0.15146579804560262" data-copyright="0" _width="614px" data-fail="0" alt="" /></p><p><span style="color: #534e4e; font-size: 15px;"><br /></span></p><p><span style="color: #534e4e; letter-spacing: 0.5px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; font-size: 15px;">这里有 3 个令人相见恨晚的奇技淫巧来简化它的使用，分别是：使用免费的 GPU、安装库、上传并使用数据文件。</span></p><p><span style="color: #534e4e; letter-spacing: 0.5px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; font-size: 15px;"><br /></span></p><p><span style="color: #534e4e; letter-spacing: 0.5px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; font-size: 15px;">下面分别介绍：</span></p><p><span style="color: #534e4e; letter-spacing: 0.5px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; font-size: 15px;"><br /></span></p><p><span style="color: #534e4e; font-size: 15px;"><strong><span style="letter-spacing: 0.5px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">1.&nbsp;使用免费的 GPU</span></strong></span></p><p><span style="color: #534e4e; letter-spacing: 0.5px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; font-size: 15px;"><br /></span></p><p><span style="color: #534e4e; letter-spacing: 0.5px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; font-size: 15px;">在打开的 Jupyter Notebook 中，选择菜单栏&#8220;<strong>代码执行程序（Runtime）</strong>&#8221;，&#8220;<strong>更改运行类型（Change runtime type）</strong>&#8221;，这时将看到以下弹出窗口：</span></p><p><img style="width: 371px !important; height: auto !important; visibility: visible !important;" src="https://mmbiz.qpic.cn/mmbiz_png/hflWRBRSEZ4HGq3Cc45aXDDNG4icg1zoYPHcvicgV7M7slNTFRiaMHHQOGVdkuBicIrZJgiaccP816DZibmGMNU5eJOw/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" crossorigin="anonymous" data-src="https://mmbiz.qpic.cn/mmbiz_png/hflWRBRSEZ4HGq3Cc45aXDDNG4icg1zoYPHcvicgV7M7slNTFRiaMHHQOGVdkuBicIrZJgiaccP816DZibmGMNU5eJOw/640?wx_fmt=png" data-w="371" data-type="png" data-s="300,640" data-ratio="0.7789757412398922" data-copyright="0" _width="371px" data-fail="0" alt="" /></p><p><span style="color: #534e4e; font-size: 15px;">确保&#8220;硬件加速器（Hardware accelerator）&#8221;设置为 GPU（默认为 CPU）。<span style="color: #444444; font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; background-color: #ffffff;">设置完毕后点击保存。</span></span></p><p><span style="color: #444444; font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px; background-color: #ffffff;"><br /></span></p><p><span style="color: #444444; font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px; background-color: #ffffff;">值得注意的是确认笔记本处于<strong>已连接</strong>的状态：</span></p><p><span style="color: #444444; font-family: &quot;Microsoft Yahei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 15px; background-color: #ffffff;"><br /></span></p><p><img style="width: 556px !important; height: auto !important; visibility: visible !important;" src="https://mmbiz.qpic.cn/mmbiz_png/hflWRBRSEZ4HGq3Cc45aXDDNG4icg1zoYBicNZr5Z3ZxfeyfoH5Z1LeCZE4ibshj4eTjcbhlU84t7uuwQ6PLoicLew/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" crossorigin="anonymous" data-src="https://mmbiz.qpic.cn/mmbiz_png/hflWRBRSEZ4HGq3Cc45aXDDNG4icg1zoYBicNZr5Z3ZxfeyfoH5Z1LeCZE4ibshj4eTjcbhlU84t7uuwQ6PLoicLew/640?wx_fmt=png" data-w="1813" data-type="png" data-s="300,640" data-ratio="0.03474903474903475" data-copyright="0" data-cropsely2="84" data-cropsely1="0" data-cropselx2="556" data-cropselx1="0" _width="556px" data-fail="0" alt="" /></p><p><br /></p><p><span style="color: red; font-size: 15px;">检查是否真的开启了 GPU（即当前连接到了GPU实例），可以直接在 Jupyter Notebook 中运行以下命令</span><span style="color: #534e4e; font-size: 15px;">：</span></p><p><span style="color: #534e4e; font-size: 15px;"><br /></span></p><section mpa-preserve="t" data-mpa-template="t" data-mpa-preserve-tpl-color="t"><pre style="background-image: none; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; margin-top: 0px; margin-bottom: 0px; padding: 0px;"><code style="background: #282c34; margin: 0px 0.15em; padding: 6px; border-radius: 4px; color: #abb2bf; font-size: 0.85em; display: block; white-space: nowrap; -ms-overflow-x: auto;">import tensorflow <span style="background: rgba(0, 0, 0, 0); width: 13px; color: #c678dd;">as</span> <span style="background: rgba(0, 0, 0, 0); width: 14px; color: #c678dd;">tf</span><br />device_name = <span style="background: rgba(0, 0, 0, 0); width: 13px; color: #c678dd;">tf</span>.test.gpu_device_name()<br /><span style="background: rgba(0, 0, 0, 0); width: 13px; color: #c678dd;">if</span> device_name != <span style="background: rgba(0, 0, 0, 0); width: 99px; color: #98c379;">'/device:GPU:0'</span>:<br /> &nbsp;raise SystemError(<span style="background: rgba(0, 0, 0, 0); width: 145px; color: #98c379;">'GPU device not found'</span>)<br /><span style="background: rgba(0, 0, 0, 0); width: 33px; color: #c678dd;">print</span>(<span style="background: rgba(0, 0, 0, 0); width: 119px; color: #98c379;">'Found GPU at: {}'</span>.format(device_name))</code></pre></section><p>&nbsp;</p><p><span style="color: red; font-size: 15px;">若输出以下语句，则表明已经使用了 GPU 实例。</span></p><p><span style="color: #534e4e; font-size: 15px;"><br /></span></p><blockquote><p><span style="color: #534e4e; font-size: 15px;">Found GPU at: /device:GPU:0</span></p></blockquote><p><span style="color: #534e4e; font-size: 15px;"><br /></span></p><p><span style="color: #534e4e; font-size: 15px;">但是，由于在线 GPU 资源有限，有时候可能会出现下面的问题提示：</span></p><p><span style="color: #534e4e; font-size: 15px;"><br /></span></p><p><img style="width: 583px !important; height: auto !important; visibility: visible !important;" src="https://mmbiz.qpic.cn/mmbiz_jpg/hflWRBRSEZ4HGq3Cc45aXDDNG4icg1zoYib3eqQnQWmXfFVYddjGDoUxib1YgjOWibOtQ29zsEsDVXWgjdbarmC3ibA/640?wx_fmt=jpeg&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" crossorigin="anonymous" data-src="https://mmbiz.qpic.cn/mmbiz_jpg/hflWRBRSEZ4HGq3Cc45aXDDNG4icg1zoYib3eqQnQWmXfFVYddjGDoUxib1YgjOWibOtQ29zsEsDVXWgjdbarmC3ibA/640?wx_fmt=jpeg" data-w="583" data-type="jpeg" data-s="300,640" data-ratio="0.30360205831903947" data-copyright="0" _width="583px" data-fail="0"  alt="" /><br /></p><p>&nbsp;<br /></p><p><span style="color: #534e4e; font-size: 15px;">就这样，谷歌允许你一次最多持续使用 12 小时的免费 GPU。</span></p><p><span style="color: #534e4e; font-size: 15px;"><br /></span></p><p><strong><span style="color: #534e4e; font-size: 15px;">2.&nbsp;<span style="letter-spacing: 0.5px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif;">安装库</span></span></strong></p><p><span style="color: #534e4e; letter-spacing: 0.5px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; font-size: 15px;"><br /></span></p><p><span style="color: #534e4e; letter-spacing: 0.5px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; font-size: 15px;">目前，在 Google Colaboratory 中安装的软件并不是持久的，意味着每次重新连接实例时都需要重新安装。但是，Colab 已经默认安装了需要有用的库，安装新的库也并非难事，方法也有好几种。</span></p><p><span style="color: #534e4e; letter-spacing: 0.5px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; font-size: 15px;"><br /></span></p><p><span style="color: #534e4e; letter-spacing: 0.5px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; font-size: 15px;">但需要注意的是，安装任何需要从源代码构建的软件可能需要很长的时间。</span></p><p><span style="color: #534e4e; letter-spacing: 0.5px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; font-size: 15px;"><br /></span></p><p><span style="color: red; letter-spacing: 0.5px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; font-size: 15px;">Colab 同时支持 pip 和 apt 包管理器。无论您使用的是哪一个，记住要在命令前面加上符号 &#8220;!&#8221;。</span></p><p><span style="color: #534e4e; letter-spacing: 0.5px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; font-size: 15px;"><br /></span></p><section mpa-preserve="t" data-mpa-template="t" data-mpa-preserve-tpl-color="t"><pre style="background-image: none; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; margin-top: 0px; margin-bottom: 0px; padding: 0px;"><code style="background: #282c34; margin: 0px 0.15em; padding: 6px; border-radius: 4px; color: #abb2bf; font-size: 0.85em; display: block; white-space: nowrap; -ms-overflow-x: auto;"><span style="background: rgba(0, 0, 0, 0); width: 6px; color: #61aeee;">#</span> Install Keras with pip<br />!pip install -q keras<br />import keras<br /><span style="background: rgba(0, 0, 0, 0); width: 6px; color: #61aeee;"><br />&gt;</span>&gt;&gt; Using TensorFlow backend.<br /><span style="background: rgba(0, 0, 0, 0); width: 6px; color: #61aeee;"><br />#</span> Install GraphViz with apt<br />!apt-get install graphviz -y</code></pre></section><p><span style="color: #534e4e; letter-spacing: 0.5px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; font-size: 15px;"><br /></span></p><p><img style="width: 677px !important; height: auto !important; visibility: visible !important;" src="https://mmbiz.qpic.cn/mmbiz_png/hflWRBRSEZ4HGq3Cc45aXDDNG4icg1zoYLRSyiaNyAFhHibfVybkQypsD9eWWxpE2mbgjDVlg1WzLAtquweCX7XjQ/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" crossorigin="anonymous" data-src="https://mmbiz.qpic.cn/mmbiz_png/hflWRBRSEZ4HGq3Cc45aXDDNG4icg1zoYLRSyiaNyAFhHibfVybkQypsD9eWWxpE2mbgjDVlg1WzLAtquweCX7XjQ/640?wx_fmt=png" data-w="719" data-type="png" data-s="300,640" data-ratio="0.56884561891516" data-copyright="0" _width="677px" data-fail="0" alt="" /></p><p><br /></p><p><strong><span style="color: #534e4e; letter-spacing: 0.5px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; font-size: 15px;">3.&nbsp;上传并使用数据文件</span></strong></p><p><span style="color: #534e4e; letter-spacing: 0.5px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; font-size: 15px;"><br /></span></p><p><span style="color: #534e4e; letter-spacing: 0.5px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; font-size: 15px;">我们一般都需要在 Colab 笔记本中使用数据，对吧？你可以使用 wget 之类的工具从网络上获取数据，<strong>但是如果你有一些本地文件，想上传到你的谷歌硬盘中的 Colab 环境里并使用它们，该怎么做呢</strong>？</span></p><p><span style="color: #534e4e; letter-spacing: 0.5px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; font-size: 15px;"><br /></span></p><p><span style="color: #534e4e; letter-spacing: 0.5px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; font-size: 15px;">很简单，只需 3 步即可实现！</span></p><p><span style="color: #534e4e; letter-spacing: 0.5px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; font-size: 15px;"><br /></span></p><p><span style="color: #534e4e; letter-spacing: 0.5px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; font-size: 15px;">首先使用以下命令调用笔记本中的文件选择器：</span></p><p><span style="color: #534e4e; letter-spacing: 0.5px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; font-size: 15px;"><br /></span></p><section mpa-preserve="t" data-mpa-template="t" data-mpa-preserve-tpl-color="t"><pre style="background-image: none; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; margin-top: 0px; margin-bottom: 0px; padding: 0px;"><code style="background: #282c34; margin: 0px 0.15em; padding: 6px; border-radius: 4px; color: #abb2bf; font-size: 0.85em; display: block; white-space: nowrap; -ms-overflow-x: auto;">from google.colab import <span style="background: rgba(0, 0, 0, 0); width: 33px; color: #c678dd;">files</span><br />uploaded = <span style="background: rgba(0, 0, 0, 0); width: 33px; color: #c678dd;">files</span>.upload()</code></pre></section><p><br /></p><p><span style="color: #534e4e; letter-spacing: 0.5px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; font-size: 15px;">运行之后，我们就会发现单元 cell 下出现了&#8220;<strong>选择文件</strong>&#8221;按钮：</span></p><p><span style="color: #534e4e; letter-spacing: 0.5px; font-family: &quot;Helvetica Neue&quot;, Helvetica, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, Arial, sans-serif; font-size: 15px;"><br /></span></p><p><img style="width: 445px !important; height: auto !important; visibility: visible !important;" src="https://mmbiz.qpic.cn/mmbiz_png/hflWRBRSEZ4HGq3Cc45aXDDNG4icg1zoYR5waPrqkerJbzS4C0EoBcLwUrta94JsTXduRmicCZVh2NxmGribFry8g/640?wx_fmt=png&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" crossorigin="anonymous" data-src="https://mmbiz.qpic.cn/mmbiz_png/hflWRBRSEZ4HGq3Cc45aXDDNG4icg1zoYR5waPrqkerJbzS4C0EoBcLwUrta94JsTXduRmicCZVh2NxmGribFry8g/640?wx_fmt=png" data-w="445" data-type="png" data-s="300,640" data-ratio="0.2247191011235955" data-copyright="0" _width="445px" data-fail="0" alt="" /></p><p><br /></p><p><span style="color: #534e4e; font-size: 15px;">这样就可以直接选择你想上传的文件啦！</span></p><p><span style="color: #534e4e; font-size: 15px;"><br /></span></p><p><span style="color: #534e4e; font-size: 15px;">选择文件后，使用以下迭代方法上传文件以查找其键名，命令如下：</span></p><p><span style="color: #534e4e; font-size: 15px;"><br /></span></p><section mpa-preserve="t" data-mpa-template="t" data-mpa-preserve-tpl-color="t"><pre style="background-image: none; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; margin-top: 0px; margin-bottom: 0px; padding: 0px;"><code style="background: #282c34; margin: 0px 0.15em; padding: 6px; border-radius: 4px; color: #abb2bf; font-size: 0.85em; display: block; white-space: nowrap; -ms-overflow-x: auto;"><span style="background: rgba(0, 0, 0, 0); width: 20px; color: #c678dd;">for</span> fn in uploaded.<span style="background: rgba(0, 0, 0, 0); width: 27px; color: #e6c07b;">keys</span>():<br /> &nbsp;<span style="background: rgba(0, 0, 0, 0); width: 33px; color: #c678dd;">print</span>(<span style="background: rgba(0, 0, 0, 0); width: 369px; color: #98c379;">'User uploaded file "{name}" with length {length} bytes'</span>.format(name=fn, length=<span style="background: rgba(0, 0, 0, 0); width: 20px; color: #e6c07b;">len</span>(uploaded[fn])))</code></pre></section><p><br /></p><p><span style="color: #534e4e; font-size: 15px;">例如待上传的是 iris.csv 文件，若运行没有问题的话，应该出现类似下面的提示语句：</span></p><p><span style="color: #534e4e; font-size: 15px;"><br /></span></p><blockquote><p><span style="color: #534e4e; font-size: 15px;">User uploaded file "iris.csv" with length 3716 bytes</span></p></blockquote><p><span style="color: #534e4e; font-size: 15px;"><br /></span></p><p><span style="color: #534e4e; font-size: 15px;">最后，就使用以下命令将文件的内容加载到 Pandas 的 DataFrame 中了：</span></p><p><span style="color: #534e4e; font-size: 15px;"><br /></span></p><section mpa-preserve="t" data-mpa-template="t" data-mpa-preserve-tpl-color="t"><pre style="background-image: none; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; margin-top: 0px; margin-bottom: 0px; padding: 0px;"><code style="background: #282c34; margin: 0px 0.15em; padding: 6px; border-radius: 4px; color: #abb2bf; font-size: 0.85em; display: block; white-space: nowrap; -ms-overflow-x: auto;"><span style="background: rgba(0, 0, 0, 0); width: 39px; color: #c678dd;">import</span> pandas <span style="background: rgba(0, 0, 0, 0); width: 13px; color: #c678dd;">as</span> pd<br /><span style="background: rgba(0, 0, 0, 0); width: 39px; color: #c678dd;">import</span> io<br />df = pd.read_csv(io.StringIO(uploaded[<span style="background: rgba(0, 0, 0, 0); width: 65px; color: #98c379;">'iris.csv'</span>].decode(<span style="background: rgba(0, 0, 0, 0); width: 46px; color: #98c379;">'utf-8'</span>)))<br />print(df)</code></pre></section><p><br /></p><p><span style="color: #534e4e; font-size: 15px;">这种上传文件的方法是不是很简单呢？当然，上传和使用数据文件还有其它的方法，但是我发现这一方法最简单明了。</span></p><p><span style="color: #534e4e; font-size: 15px;"><br /></span></p><p><span style="color: #534e4e; font-size: 15px;">以上就是关于 Google Calaboratory 的 3 个非常实用的技巧，赶紧尝试一下吧！</span></p><p><span style="color: #534e4e; font-size: 15px;"><br /></span></p><p><span style="color: #534e4e; font-size: 15px;">最后，可能有的读者朋友对&nbsp;Google Calaboratory 不太了解的，可以查看我之前写的一篇文章：</span><span style="color: #534e4e; font-size: 15px; text-decoration-line: underline;"><strong>如何在免费云端运行 Python 深度学习框架？</strong></span><span style="color: #534e4e; font-size: 15px;">链接如下：</span></p><p><span style="color: #534e4e; font-size: 15px; text-decoration-line: underline;"><strong><br /></strong></span></p><p><span style="color: #534e4e; font-size: 15px;">https://redstonewill.com/1493/</span></p><p><span style="color: #534e4e; font-size: 15px;"><br /></span></p><p><span style="color: #534e4e; font-size: 15px;">也可以点击<strong>阅读原文</strong>查看！</span></p><br />Reference:<br /><div>https://mp.weixin.qq.com/s/vLnBFPZNvIjs4R7d4_6M_g</div><img src ="http://www.cppblog.com/guijie/aggbug/216240.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guijie/" target="_blank">杰哥</a> 2019-02-13 23:56 <a href="http://www.cppblog.com/guijie/archive/2019/02/13/216240.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[zz]Python中下划线的5种含义</title><link>http://www.cppblog.com/guijie/archive/2019/02/02/216230.html</link><dc:creator>杰哥</dc:creator><author>杰哥</author><pubDate>Fri, 01 Feb 2019 17:51:00 GMT</pubDate><guid>http://www.cppblog.com/guijie/archive/2019/02/02/216230.html</guid><wfw:comment>http://www.cppblog.com/guijie/comments/216230.html</wfw:comment><comments>http://www.cppblog.com/guijie/archive/2019/02/02/216230.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guijie/comments/commentRss/216230.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guijie/services/trackbacks/216230.html</trackback:ping><description><![CDATA[<div><div style="overflow: hidden; width: 690px; margin: 0px auto; color: #1a1a1a; font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; font-size: medium; background-color: #ffffff;"><div ztext=""  post-richtext"="" style="word-break: break-word; line-height: 1.6; margin-top: 20px;"><p style="margin: 0px 0px 1.4em;">分享一篇文章：<a href="http://link.zhihu.com/?target=https%3A//dbader.org/blog/meaning-of-underscores-in-python" wrap=""  external"="" target="_blank" rel="nofollow noreferrer" data-za-detail-view-id="1043" style="text-decoration-line: none; cursor: pointer; border-bottom: 1px solid #808080;">The Meaning of Underscores in Python</a>。</p><p style="margin: 1.4em 0px;">本文介绍了Python中单下划线和双下划线（"dunder"）的各种含义和命名约定，名称修饰（name mangling）的工作原理，以及它如何影响你自己的Python类。</p><p style="margin: 1.4em 0px;">单下划线和双下划线在Python变量和方法名称中都各有其含义。有一些含义仅仅是依照约定，被视作是对程序员的提示 - 而有一些含义是由Python解释器严格执行的。</p><p style="margin: 1.4em 0px;">如果你想知道&#8220;Python变量和方法名称中单下划线和双下划线的含义是什么？&#8221;，我会尽我所能在这里为你解答。</p><p style="margin: 1.4em 0px;">在本文中，我将讨论以下五种下划线模式和命名约定，以及它们如何影响Python程序的行为：</p><ul style="padding: 0px; margin: 1.4em 0px; display: table;"><li style="list-style: none; display: table-row;">单前导下划线：_var</li><li style="list-style: none; display: table-row;">单末尾下划线：var_</li><li style="list-style: none; display: table-row;">双前导下划线：__var</li><li style="list-style: none; display: table-row;">双前导和末尾下划线：__var__</li><li style="list-style: none; display: table-row;">单下划线：_</li></ul><p style="margin: 1.4em 0px;">在文章结尾处，你可以找到一个简短的&#8220;速查表&#8221;，总结了五种不同的下划线命名约定及其含义，以及一个简短的视频教程，可让你亲身体验它们的行为。</p><p style="margin: 1.4em 0px;">让我们马上开始！</p><h2>1. 单前导下划线 _var</h2><p style="margin: 1.4em 0px;">当涉及到变量和方法名称时，单个下划线前缀有一个约定俗成的含义。 它是对程序员的一个提示 - 意味着Python社区一致认为它应该是什么意思，但程序的行为不受影响。</p><p style="margin: 1.4em 0px;">下划线前缀的含义是告知其他程序员：以单个下划线开头的变量或方法仅供内部使用。 该约定在PEP 8中有定义。</p><p style="margin: 1.4em 0px;">这不是Python强制规定的。 Python不像Java那样在&#8220;私有&#8221;和&#8220;公共&#8221;变量之间有很强的区别。 这就像有人提出了一个小小的下划线警告标志，说：</p><blockquote style="margin: 1.4em 0px; padding-left: 1em; color: #646464; border-left-width: 3px; border-left-color: #d3d3d3;">&#8220;嘿，这不是真的要成为类的公共接口的一部分。不去管它就好。&#8220;</blockquote><p style="margin: 1.4em 0px;">看看下面的例子：</p><div style="margin: 1em 0px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: calc(0.888889em); font-size: 0.9em; word-break: initial; overflow-wrap: initial; overflow: auto; background: #f6f6f6; border-radius: 4px;"><code style="margin: 0px; padding: 0px; border-radius: 0px; font-family: Menlo, Monaco, Consolas, &quot;Andale Mono&quot;, &quot;lucida console&quot;, &quot;Courier New&quot;, monospace; font-size: inherit; background-color: inherit;">class Test:    def __init__(self):        self.foo = 11        self._bar = 23 </code></pre></div><p style="margin: 1.4em 0px;">如果你实例化此类，并尝试访问在__init__构造函数中定义的foo和_bar属性，会发生什么情况？ 让我们来看看：</p><div style="margin: 1em 0px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: calc(0.888889em); font-size: 0.9em; word-break: initial; overflow-wrap: initial; overflow: auto; background: #f6f6f6; border-radius: 4px;"><code style="margin: 0px; padding: 0px; border-radius: 0px; font-family: Menlo, Monaco, Consolas, &quot;Andale Mono&quot;, &quot;lucida console&quot;, &quot;Courier New&quot;, monospace; font-size: inherit; background-color: inherit;">&gt;&gt;&gt; t = Test() &gt;&gt;&gt; t.foo 11 &gt;&gt;&gt; t._bar 23 </code></pre></div><p style="margin: 1.4em 0px;">你会看到_bar中的单个下划线并没有阻止我们&#8220;进入&#8221;类并访问该变量的值。</p><p style="margin: 1.4em 0px;">这是因为Python中的单个下划线前缀仅仅是一个约定 - 至少相对于变量和方法名而言。</p><p style="margin: 1.4em 0px;">但是，前导下划线的确会影响从模块中导入名称的方式。</p><p style="margin: 1.4em 0px;">假设你在一个名为my_module的模块中有以下代码：</p><div style="margin: 1em 0px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: calc(0.888889em); font-size: 0.9em; word-break: initial; overflow-wrap: initial; overflow: auto; background: #f6f6f6; border-radius: 4px;"><code style="margin: 0px; padding: 0px; border-radius: 0px; font-family: Menlo, Monaco, Consolas, &quot;Andale Mono&quot;, &quot;lucida console&quot;, &quot;Courier New&quot;, monospace; font-size: inherit; background-color: inherit;"># This is my_module.py:  def external_func():    return 23  def _internal_func():    return 42 </code></pre></div><p style="margin: 1.4em 0px;">现在，如果使用通配符从模块中导入所有名称，则Python不会导入带有前导下划线的名称（除非模块定义了覆盖此行为的__all__列表）：</p><div style="margin: 1em 0px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: calc(0.888889em); font-size: 0.9em; word-break: initial; overflow-wrap: initial; overflow: auto; background: #f6f6f6; border-radius: 4px;"><code style="margin: 0px; padding: 0px; border-radius: 0px; font-family: Menlo, Monaco, Consolas, &quot;Andale Mono&quot;, &quot;lucida console&quot;, &quot;Courier New&quot;, monospace; font-size: inherit; background-color: inherit;">&gt;&gt;&gt; from my_module import * &gt;&gt;&gt; external_func() 23 &gt;&gt;&gt; _internal_func() NameError: "name '_internal_func' is not defined" </code></pre></div><p style="margin: 1.4em 0px;">顺便说一下，应该避免通配符导入，因为它们使名称空间中存在哪些名称不清楚。 为了清楚起见，坚持常规导入更好。<br /></p><p style="margin: 1.4em 0px;">与通配符导入不同，常规导入不受前导单个下划线命名约定的影响：</p><div style="margin: 1em 0px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: calc(0.888889em); font-size: 0.9em; word-break: initial; overflow-wrap: initial; overflow: auto; background: #f6f6f6; border-radius: 4px;"><code style="margin: 0px; padding: 0px; border-radius: 0px; font-family: Menlo, Monaco, Consolas, &quot;Andale Mono&quot;, &quot;lucida console&quot;, &quot;Courier New&quot;, monospace; font-size: inherit; background-color: inherit;">&gt;&gt;&gt; import my_module &gt;&gt;&gt; my_module.external_func() 23 &gt;&gt;&gt; my_module._internal_func() 42 </code></pre></div><p style="margin: 1.4em 0px;">我知道这一点可能有点令人困惑。 如果你遵循PEP 8推荐，避免通配符导入，那么你真正需要记住的只有这个：</p><blockquote style="margin: 1.4em 0px; padding-left: 1em; color: #646464; border-left-width: 3px; border-left-color: #d3d3d3;">单个下划线是一个Python命名约定，表示这个名称是供内部使用的。 它通常不由Python解释器强制执行，仅仅作为一种对程序员的提示。</blockquote><h2>2. 单末尾下划线 var_</h2><p style="margin: 1.4em 0px;">有时候，一个变量的最合适的名称已经被一个关键字所占用。 因此，像class或def这样的名称不能用作Python中的变量名称。 在这种情况下，你可以附加一个下划线来解决命名冲突：</p><div style="margin: 1em 0px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: calc(0.888889em); font-size: 0.9em; word-break: initial; overflow-wrap: initial; overflow: auto; background: #f6f6f6; border-radius: 4px;"><code style="margin: 0px; padding: 0px; border-radius: 0px; font-family: Menlo, Monaco, Consolas, &quot;Andale Mono&quot;, &quot;lucida console&quot;, &quot;Courier New&quot;, monospace; font-size: inherit; background-color: inherit;">&gt;&gt;&gt; def make_object(name, class): SyntaxError: "invalid syntax"  &gt;&gt;&gt; def make_object(name, class_): ...    pass </code></pre></div><p style="margin: 1.4em 0px;">总之，单个末尾下划线（后缀）是一个约定，用来避免与Python关键字产生命名冲突。 PEP 8解释了这个约定。</p><h2>3. 双前导下划线 __var</h2><p style="margin: 1.4em 0px;">到目前为止，我们所涉及的所有命名模式的含义，来自于已达成共识的约定。 而对于以双下划线开头的Python类的属性（包括变量和方法），情况就有点不同了。</p><p style="margin: 1.4em 0px;">双下划线前缀会导致Python解释器重写属性名称，以避免子类中的命名冲突。</p><p style="margin: 1.4em 0px;">这也叫做名称修饰（name mangling） - 解释器更改变量的名称，以便在类被扩展的时候不容易产生冲突。</p><p style="margin: 1.4em 0px;">我知道这听起来很抽象。 因此，我组合了一个小小的代码示例来予以说明：</p><div style="margin: 1em 0px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: calc(0.888889em); font-size: 0.9em; word-break: initial; overflow-wrap: initial; overflow: auto; background: #f6f6f6; border-radius: 4px;"><code style="margin: 0px; padding: 0px; border-radius: 0px; font-family: Menlo, Monaco, Consolas, &quot;Andale Mono&quot;, &quot;lucida console&quot;, &quot;Courier New&quot;, monospace; font-size: inherit; background-color: inherit;">class Test:    def __init__(self):        self.foo = 11        self._bar = 23        self.__baz = 23 </code></pre></div><p style="margin: 1.4em 0px;">让我们用内置的dir()函数来看看这个对象的属性：</p><div style="margin: 1em 0px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: calc(0.888889em); font-size: 0.9em; word-break: initial; overflow-wrap: initial; overflow: auto; background: #f6f6f6; border-radius: 4px;"><code style="margin: 0px; padding: 0px; border-radius: 0px; font-family: Menlo, Monaco, Consolas, &quot;Andale Mono&quot;, &quot;lucida console&quot;, &quot;Courier New&quot;, monospace; font-size: inherit; background-color: inherit;">&gt;&gt;&gt; t = Test() &gt;&gt;&gt; dir(t) ['_Test__baz', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_bar', 'foo'] </code></pre></div><p style="margin: 1.4em 0px;">以上是这个对象属性的列表。 让我们来看看这个列表，并寻找我们的原始变量名称foo，_bar和__baz - 我保证你会注意到一些有趣的变化。<br /></p><ul style="padding: 0px; margin: 1.4em 0px; display: table;"><li style="list-style: none; display: table-row;">self.foo变量在属性列表中显示为未修改为foo。</li><li style="list-style: none; display: table-row;">self._bar的行为方式相同 - 它以_bar的形式显示在类上。 就像我之前说过的，在这种情况下，前导下划线仅仅是一个约定。 给程序员一个提示而已。</li><li style="list-style: none; display: table-row;">然而，对于self.__baz而言，情况看起来有点不同。 当你在该列表中搜索__baz时，你会看不到有这个名字的变量。</li></ul><p style="margin: 1.4em 0px;">__baz出什么情况了？</p><p style="margin: 1.4em 0px;">如果你仔细观察，你会看到此对象上有一个名为_Test__baz的属性。 这就是Python解释器所做的名称修饰。 它这样做是为了防止变量在子类中被重写。</p><p style="margin: 1.4em 0px;">让我们创建另一个扩展Test类的类，并尝试重写构造函数中添加的现有属性：</p><div style="margin: 1em 0px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: calc(0.888889em); font-size: 0.9em; word-break: initial; overflow-wrap: initial; overflow: auto; background: #f6f6f6; border-radius: 4px;"><code style="margin: 0px; padding: 0px; border-radius: 0px; font-family: Menlo, Monaco, Consolas, &quot;Andale Mono&quot;, &quot;lucida console&quot;, &quot;Courier New&quot;, monospace; font-size: inherit; background-color: inherit;">class ExtendedTest(Test):    def __init__(self):        super().__init__()        self.foo = 'overridden'        self._bar = 'overridden'        self.__baz = 'overridden' </code></pre></div><p style="margin: 1.4em 0px;">现在，你认为foo，_bar和__baz的值会出现在这个ExtendedTest类的实例上吗？ 我们来看一看：</p><div style="margin: 1em 0px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: calc(0.888889em); font-size: 0.9em; word-break: initial; overflow-wrap: initial; overflow: auto; background: #f6f6f6; border-radius: 4px;"><code style="margin: 0px; padding: 0px; border-radius: 0px; font-family: Menlo, Monaco, Consolas, &quot;Andale Mono&quot;, &quot;lucida console&quot;, &quot;Courier New&quot;, monospace; font-size: inherit; background-color: inherit;">&gt;&gt;&gt; t2 = ExtendedTest() &gt;&gt;&gt; t2.foo 'overridden' &gt;&gt;&gt; t2._bar 'overridden' &gt;&gt;&gt; t2.__baz AttributeError: "'ExtendedTest' object has no attribute '__baz'" </code></pre></div><p style="margin: 1.4em 0px;">等一下，当我们尝试查看t2 .__ baz的值时，为什么我们会得到AttributeError？ 名称修饰被再次触发了！ 事实证明，这个对象甚至没有__baz属性：</p><div style="margin: 1em 0px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: calc(0.888889em); font-size: 0.9em; word-break: initial; overflow-wrap: initial; overflow: auto; background: #f6f6f6; border-radius: 4px;"><code style="margin: 0px; padding: 0px; border-radius: 0px; font-family: Menlo, Monaco, Consolas, &quot;Andale Mono&quot;, &quot;lucida console&quot;, &quot;Courier New&quot;, monospace; font-size: inherit; background-color: inherit;">&gt;&gt;&gt; dir(t2) ['_ExtendedTest__baz', '_Test__baz', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_bar', 'foo', 'get_vars'] </code></pre></div><p style="margin: 1.4em 0px;">正如你可以看到__baz变成_ExtendedTest__baz以防止意外修改：</p><div style="margin: 1em 0px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: calc(0.888889em); font-size: 0.9em; word-break: initial; overflow-wrap: initial; overflow: auto; background: #f6f6f6; border-radius: 4px;"><code style="margin: 0px; padding: 0px; border-radius: 0px; font-family: Menlo, Monaco, Consolas, &quot;Andale Mono&quot;, &quot;lucida console&quot;, &quot;Courier New&quot;, monospace; font-size: inherit; background-color: inherit;">&gt;&gt;&gt; t2._ExtendedTest__baz 'overridden' </code></pre></div><p style="margin: 1.4em 0px;">但原来的_Test__baz还在：</p><div style="margin: 1em 0px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: calc(0.888889em); font-size: 0.9em; word-break: initial; overflow-wrap: initial; overflow: auto; background: #f6f6f6; border-radius: 4px;"><code style="margin: 0px; padding: 0px; border-radius: 0px; font-family: Menlo, Monaco, Consolas, &quot;Andale Mono&quot;, &quot;lucida console&quot;, &quot;Courier New&quot;, monospace; font-size: inherit; background-color: inherit;">&gt;&gt;&gt; t2._Test__baz 42 </code></pre></div><p style="margin: 1.4em 0px;">双下划线名称修饰对程序员是完全透明的。 下面的例子证实了这一点：</p><div style="margin: 1em 0px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: calc(0.888889em); font-size: 0.9em; word-break: initial; overflow-wrap: initial; overflow: auto; background: #f6f6f6; border-radius: 4px;"><code style="margin: 0px; padding: 0px; border-radius: 0px; font-family: Menlo, Monaco, Consolas, &quot;Andale Mono&quot;, &quot;lucida console&quot;, &quot;Courier New&quot;, monospace; font-size: inherit; background-color: inherit;">class ManglingTest:    def __init__(self):        self.__mangled = 'hello'     def get_mangled(self):        return self.__mangled  &gt;&gt;&gt; ManglingTest().get_mangled() 'hello' &gt;&gt;&gt; ManglingTest().__mangled AttributeError: "'ManglingTest' object has no attribute '__mangled'" </code></pre></div><p style="margin: 1.4em 0px;">名称修饰是否也适用于方法名称？ 是的，也适用。名称修饰会影响在一个类的上下文中，以两个下划线字符（"dunders"）开头的<span style="font-weight: 600;">所有</span>名称：</p><div style="margin: 1em 0px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: calc(0.888889em); font-size: 0.9em; word-break: initial; overflow-wrap: initial; overflow: auto; background: #f6f6f6; border-radius: 4px;"><code style="margin: 0px; padding: 0px; border-radius: 0px; font-family: Menlo, Monaco, Consolas, &quot;Andale Mono&quot;, &quot;lucida console&quot;, &quot;Courier New&quot;, monospace; font-size: inherit; background-color: inherit;">class MangledMethod:    def __method(self):        return 42     def call_it(self):        return self.__method()  &gt;&gt;&gt; MangledMethod().__method() AttributeError: "'MangledMethod' object has no attribute '__method'" &gt;&gt;&gt; MangledMethod().call_it() 42 </code></pre></div><p style="margin: 1.4em 0px;">这是另一个也许令人惊讶的运用名称修饰的例子：</p><div style="margin: 1em 0px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: calc(0.888889em); font-size: 0.9em; word-break: initial; overflow-wrap: initial; overflow: auto; background: #f6f6f6; border-radius: 4px;"><code style="margin: 0px; padding: 0px; border-radius: 0px; font-family: Menlo, Monaco, Consolas, &quot;Andale Mono&quot;, &quot;lucida console&quot;, &quot;Courier New&quot;, monospace; font-size: inherit; background-color: inherit;">_MangledGlobal__mangled = 23  class MangledGlobal:    def test(self):        return __mangled  &gt;&gt;&gt; MangledGlobal().test() 23 </code></pre></div><p style="margin: 1.4em 0px;">在这个例子中，我声明了一个名为_MangledGlobal__mangled的全局变量。然后我在名为MangledGlobal的类的上下文中访问变量。由于名称修饰，我能够在类的test()方法内，以__mangled来引用_MangledGlobal__mangled全局变量。<br /><br />Python解释器自动将名称__mangled扩展为_MangledGlobal__mangled，因为它以两个下划线字符开头。这表明名称修饰不是专门与类属性关联的。它适用于在类上下文中使用的两个下划线字符开头的任何名称。<br /><br />有很多要吸收的内容吧。<br /><br />老实说，这些例子和解释不是从我脑子里蹦出来的。我作了一些研究和加工才弄出来。我一直使用Python，有很多年了，但是像这样的规则和特殊情况并不总是浮现在脑海里。<br /><br />有时候程序员最重要的技能是&#8220;模式识别&#8221;，而且知道在哪里查阅信息。如果您在这一点上感到有点不知所措，请不要担心。慢慢来，试试这篇文章中的一些例子。<br /><br />让这些概念完全沉浸下来，以便你能够理解名称修饰的总体思路，以及我向您展示的一些其他的行为。如果有一天你和它们不期而遇，你会知道在文档中按什么来查。</p><h2>4. 双前导和双末尾下划线 _var_</h2><p style="margin: 1.4em 0px;">也许令人惊讶的是，如果一个名字同时以双下划线开始和结束，则不会应用名称修饰。 由双下划线前缀和后缀包围的变量不会被Python解释器修改：</p><div style="margin: 1em 0px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: calc(0.888889em); font-size: 0.9em; word-break: initial; overflow-wrap: initial; overflow: auto; background: #f6f6f6; border-radius: 4px;"><code style="margin: 0px; padding: 0px; border-radius: 0px; font-family: Menlo, Monaco, Consolas, &quot;Andale Mono&quot;, &quot;lucida console&quot;, &quot;Courier New&quot;, monospace; font-size: inherit; background-color: inherit;">class PrefixPostfixTest:    def __init__(self):        self.__bam__ = 42  &gt;&gt;&gt; PrefixPostfixTest().__bam__ 42 </code></pre></div><p style="margin: 1.4em 0px;">但是，Python保留了有双前导和双末尾下划线的名称，用于特殊用途。 这样的例子有，__init__对象构造函数，或__call__ --- 它使得一个对象可以被调用。</p><p style="margin: 1.4em 0px;">这些dunder方法通常被称为神奇方法 - 但Python社区中的许多人（包括我自己）都不喜欢这种方法。</p><p style="margin: 1.4em 0px;">最好避免在自己的程序中使用以双下划线（&#8220;dunders&#8221;）开头和结尾的名称，以避免与将来Python语言的变化产生冲突。</p><h2>5.单下划线 _</h2><p style="margin: 1.4em 0px;">按照习惯，有时候单个独立下划线是用作一个名字，来表示某个变量是临时的或无关紧要的。<br /></p><p style="margin: 1.4em 0px;">例如，在下面的循环中，我们不需要访问正在运行的索引，我们可以使用&#8220;_&#8221;来表示它只是一个临时值：</p><div style="margin: 1em 0px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: calc(0.888889em); font-size: 0.9em; word-break: initial; overflow-wrap: initial; overflow: auto; background: #f6f6f6; border-radius: 4px;"><code style="margin: 0px; padding: 0px; border-radius: 0px; font-family: Menlo, Monaco, Consolas, &quot;Andale Mono&quot;, &quot;lucida console&quot;, &quot;Courier New&quot;, monospace; font-size: inherit; background-color: inherit;">&gt;&gt;&gt; for _ in range(32): ...    print('Hello, World.') </code></pre></div><p style="margin: 1.4em 0px;">你也可以在拆分(unpacking)表达式中将单个下划线用作&#8220;不关心的&#8221;变量，以忽略特定的值。 同样，这个含义只是&#8220;依照约定&#8221;，并不会在Python解释器中触发特殊的行为。 单个下划线仅仅是一个有效的变量名称，会有这个用途而已。</p><p style="margin: 1.4em 0px;">在下面的代码示例中，我将汽车元组拆分为单独的变量，但我只对颜色和里程值感兴趣。 但是，为了使拆分表达式成功运行，我需要将包含在元组中的所有值分配给变量。 在这种情况下，&#8220;_&#8221;作为占位符变量可以派上用场：</p><div style="margin: 1em 0px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: calc(0.888889em); font-size: 0.9em; word-break: initial; overflow-wrap: initial; overflow: auto; background: #f6f6f6; border-radius: 4px;"><code style="margin: 0px; padding: 0px; border-radius: 0px; font-family: Menlo, Monaco, Consolas, &quot;Andale Mono&quot;, &quot;lucida console&quot;, &quot;Courier New&quot;, monospace; font-size: inherit; background-color: inherit;">&gt;&gt;&gt; car = ('red', 'auto', 12, 3812.4) &gt;&gt;&gt; color, _, _, mileage = car  &gt;&gt;&gt; color 'red' &gt;&gt;&gt; mileage 3812.4 &gt;&gt;&gt; _ 12 </code></pre></div><p style="margin: 1.4em 0px;">除了用作临时变量之外，&#8220;_&#8221;是大多数Python REPL中的一个特殊变量，它表示由解释器评估的最近一个表达式的结果。</p><p style="margin: 1.4em 0px;">这样就很方便了，比如你可以在一个解释器会话中访问先前计算的结果，或者，你是在动态构建多个对象并与它们交互，无需事先给这些对象分配名字：</p><div style="margin: 1em 0px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: calc(0.888889em); font-size: 0.9em; word-break: initial; overflow-wrap: initial; overflow: auto; background: #f6f6f6; border-radius: 4px;"><code style="margin: 0px; padding: 0px; border-radius: 0px; font-family: Menlo, Monaco, Consolas, &quot;Andale Mono&quot;, &quot;lucida console&quot;, &quot;Courier New&quot;, monospace; font-size: inherit; background-color: inherit;">&gt;&gt;&gt; 20 + 3 23 &gt;&gt;&gt; _ 23 &gt;&gt;&gt; print(_) 23  &gt;&gt;&gt; list() [] &gt;&gt;&gt; _.append(1) &gt;&gt;&gt; _.append(2) &gt;&gt;&gt; _.append(3) &gt;&gt;&gt; _ [1, 2, 3] </code></pre></div><h2>Python下划线命名模式 - 小结</h2><p style="margin: 1.4em 0px;">以下是一个简短的小结，即&#8220;速查表&#8221;，罗列了我在本文中谈到的五种Python下划线模式的含义：</p><figure style="margin: 1.4em 0px;"><img src="https://pic3.zhimg.com/80/v2-cbc5c6037101c7d33cf0acd9f00a8cfa_hd.jpg" data-caption="" data-size="normal" data-rawwidth="732" data-rawheight="314" zh-lightbox-thumb=""  lazy"="" width="732" data-original="https://pic3.zhimg.com/v2-cbc5c6037101c7d33cf0acd9f00a8cfa_r.jpg" data-actualsrc="https://pic3.zhimg.com/v2-cbc5c6037101c7d33cf0acd9f00a8cfa_b.jpg" style="display: block; max-width: 100%; margin: 0px auto; cursor: zoom-in;"  alt="" /></figure><hr style="margin: 4em auto; width: 240px; max-width: 100%; border-right: none; border-bottom: none; border-left: none; border-image: initial; border-top-style: solid; border-top-color: #d3d3d3;" /><p style="margin: 1.4em 0px;">你想更深入了解学习Python知识体系，你可以看一下我们花费了一个多月整理了上百小时的几百个知识点体系内容：</p><p style="margin: 1.4em 0px 0px;"><a href="http://link.zhihu.com/?target=http%3A//www.magedu.com/73198.html/%3FPython_wenzhang_zhihu_jinke_16daopythonmiansiti_34019714" wrap=""  external"="" target="_blank" rel="nofollow noreferrer" data-za-detail-view-id="1043" style="text-decoration-line: none; cursor: pointer; border-bottom: 1px solid #808080;">【超全整理】《Python自动化全能开发从入门到精通》python基础教程笔记</a></p></div></div><div style="margin: 0px auto; color: #8590a6; padding-top: 16px; padding-bottom: 16px; overflow: hidden; width: 690px; font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; background-color: #ffffff;">发布于 2018-04-26</div><div style="overflow: hidden; width: 690px; margin: 0px auto; display: flex; color: #1a1a1a; font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; font-size: medium; background-color: #ffffff;"><div post-topics"="" style="display: flex; flex-flow: row wrap; align-items: center; margin-bottom: -10px; padding-top: 16px; padding-bottom: 16px;"><div topic"="" data-za-detail-view-path-module="TopicItem" data-za-extra-module="{&quot;card&quot;:{&quot;content&quot;:{&quot;type&quot;:&quot;Topic&quot;,&quot;token&quot;:&quot;19552832&quot;}}}" style="position: relative; display: inline-block; height: 33px; padding-right: 12px; padding-left: 12px; font-size: 13px; line-height: 33px; color: #0084ff; vertical-align: top; border-radius: 100px; background: rgba(0, 132, 255, 0.1); margin-right: 5px; overflow: hidden; margin-bottom: 10px;"><a href="https://www.zhihu.com/topic/19552832" target="_blank" style="text-decoration-line: none;"><div style="position: relative; display: inline-block;"><div id="Popover3-toggle" aria-haspopup="true" aria-expanded="false" aria-owns="Popover3-content">Python</div></div></a></div></div></div><br />Reference:<br />https://zhuanlan.zhihu.com/p/36173202</div><img src ="http://www.cppblog.com/guijie/aggbug/216230.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guijie/" target="_blank">杰哥</a> 2019-02-02 01:51 <a href="http://www.cppblog.com/guijie/archive/2019/02/02/216230.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[zz]Python3中map函数的问题</title><link>http://www.cppblog.com/guijie/archive/2019/01/03/216164.html</link><dc:creator>杰哥</dc:creator><author>杰哥</author><pubDate>Thu, 03 Jan 2019 04:01:00 GMT</pubDate><guid>http://www.cppblog.com/guijie/archive/2019/01/03/216164.html</guid><wfw:comment>http://www.cppblog.com/guijie/comments/216164.html</wfw:comment><comments>http://www.cppblog.com/guijie/archive/2019/01/03/216164.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guijie/comments/commentRss/216164.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guijie/services/trackbacks/216164.html</trackback:ping><description><![CDATA[<div>Python3中map函数</div><div>在Python2中map函数会返回一个list列表，如代码：</div><div>&gt;&gt;&gt; def f(x, y): return (x, y)</div><div>&gt;&gt;&gt; l1 = [ 0, 1, 2, 3, 4, 5, 6 ]</div><div>&gt;&gt;&gt; l2 = [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ]</div><div></div><div>返回结果如下：</div><div>&gt;&gt;&gt; map(f, l1, l2)</div><div>[(0, 'Sun'), (1, 'Mon'), (2, 'Tue'), (3, 'Wed'), (4, 'Thu'), (5, 'Fri'), (6, 'Sat')]</div><div></div><div>但是，在Python3中返回结果如下：</div><div>&gt;&gt;&gt; map(f1, l1, l2)</div><div>&lt;map object at 0x00000000021DA860&gt;</div><div></div><div>如果想要得到Python2的那种结果，即返回list列表，那么必须用list作用于map，如下：</div><div>&gt;&gt;&gt; list(map(f1, l1, l2))</div><div>[(0, 'Sun'), (1, 'Mon'), (2, 'Tue'), (3, 'Wed'), (4, 'Thu'), (5, 'Fri'), (6, 'Sat')]<br /><br />reference:<br /><div>https://blog.csdn.net/u010376788/article/details/48230257</div></div><img src ="http://www.cppblog.com/guijie/aggbug/216164.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guijie/" target="_blank">杰哥</a> 2019-01-03 12:01 <a href="http://www.cppblog.com/guijie/archive/2019/01/03/216164.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[zz]python求数字位数的方法</title><link>http://www.cppblog.com/guijie/archive/2018/12/29/216152.html</link><dc:creator>杰哥</dc:creator><author>杰哥</author><pubDate>Sat, 29 Dec 2018 06:00:00 GMT</pubDate><guid>http://www.cppblog.com/guijie/archive/2018/12/29/216152.html</guid><wfw:comment>http://www.cppblog.com/guijie/comments/216152.html</wfw:comment><comments>http://www.cppblog.com/guijie/archive/2018/12/29/216152.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guijie/comments/commentRss/216152.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guijie/services/trackbacks/216152.html</trackback:ping><description><![CDATA[<p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; color: #333333; font-family: &quot;Microsoft Yahei&quot;, Simsun, Arial; background-color: #ffffff;">第一种：<br style="margin: 0px; padding: 0px;" />利用str()函数将数字转化成字符串，再利用len()函数判断位长。</p><div style="margin: 5px 0px; font-size: 12px !important;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow-wrap: break-word; font-family: &quot;Courier New&quot; !important;"><span style="margin: 0px; padding: 0px; color: #008080; line-height: 1.5 !important;"></span><span style="margin: 0px; padding: 0px; color: #008080; line-height: 1.5 !important;"> 1</span> a=Int(<span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">raw_input</span>("<span style="margin: 0px; padding: 0px; color: #8b0000; line-height: 1.5 !important;">the number you want type in:</span>") <span style="margin: 0px; padding: 0px; color: #008080; line-height: 1.5 !important;">  <br /> 2</span> b=len(str(a)) <span style="margin: 0px; padding: 0px; color: #008080; line-height: 1.5 !important;">  <br /> 3</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">print</span> b</pre></div><p style="margin-top: 10px; margin-bottom: 10px; padding: 0px; color: #333333; font-family: &quot;Microsoft Yahei&quot;, Simsun, Arial; background-color: #ffffff;">第二种：<br style="margin: 0px; padding: 0px;" />利用除10取商，通过循环次数判断位数。</p><div style="margin: 5px 0px;"><div style="font-size: 12px !important; margin: 5px 0px 0px;"><span style="margin: 0px; padding: 0px 5px 0px 0px; line-height: 1.5 !important;"><a title="复制代码" style="margin: 0px; padding: 0px; border: none !important;"></a></span></div><div>c=0</div><div>a=int(raw_input("the number you want type in:"))</div><div>while a!=0:</div><div>&nbsp; &nbsp; &nbsp; a=a/10</div><div>&nbsp; &nbsp; &nbsp; c +=1</div><div>print c</div><pre style="font-size: 12px !important; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow-wrap: break-word; font-family: &quot;Courier New&quot; !important;"><br /><br />Reference:<br /><br /><div>https://www.cnblogs.com/54Leo/p/6133270.html</div></pre></div><img src ="http://www.cppblog.com/guijie/aggbug/216152.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guijie/" target="_blank">杰哥</a> 2018-12-29 14:00 <a href="http://www.cppblog.com/guijie/archive/2018/12/29/216152.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>colab</title><link>http://www.cppblog.com/guijie/archive/2018/12/21/216130.html</link><dc:creator>杰哥</dc:creator><author>杰哥</author><pubDate>Fri, 21 Dec 2018 01:07:00 GMT</pubDate><guid>http://www.cppblog.com/guijie/archive/2018/12/21/216130.html</guid><wfw:comment>http://www.cppblog.com/guijie/comments/216130.html</wfw:comment><comments>http://www.cppblog.com/guijie/archive/2018/12/21/216130.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guijie/comments/commentRss/216130.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guijie/services/trackbacks/216130.html</trackback:ping><description><![CDATA[You can run the deep learning on the cloud without GPU. Zhengxia says that you can run 01_basics.ipynb&nbsp;using colab. Colab will use your gmail&nbsp;account. Upload your file. Edit -&gt; Notebook settings, Runtime type selects Python 3 and Hardware accelerator selects GPU.<br /><br /><div>How to create a folder in colab? 谷歌搜索: colab new folder找到这个链接: https://medium.com/lean-in-women-in-tech-india/google-colab-the-beginners-guide-5ad3b417dfa</div><div>Create a Colab Notebook</div><div>Open Google Colab.</div><div>Click on &#8216;New Notebook&#8217; and select Python 2 notebook or Python 3 notebook.</div><div>OR</div><div>Open Google Drive.</div><div>Create a new folder for the project.</div><div>Click on &#8216;New&#8217; &gt; &#8216;More&#8217; &gt; &#8216;Colaboratory&#8217;.</div><div>Google Drive -&gt; 我的云端硬盘 -&gt; 新建文件夹. Click on &#8216;New&#8217; &gt; &#8216;More&#8217; &gt; &#8216;Colaboratory&#8217;,这个怎么操作? 例如选中"02_backprop.ipynb", 打开方式, 关联更多应用, 选择colab. 这样在google drive里就可以选中"02_backprop.ipynb", 打开方式, &#8216;Colaboratory&#8217;即可.但直接打开Colab, Google drive里面是没有"02_backprop.ipynb", Recent有。暂不折腾这个问题, Zhengxia说colab应该会删,否则大家都把它当网盘使用<br /><br /><div>02_backprop.ipynb, 最开始Forward propagation上面, device改为GPU (device = torch.device('cuda') # Uncomment this to run on GPU),没法运行原因? zhengxia&nbsp;says: Edit -&gt; Notepad settings -&gt; select GPU.如果一个新电脑，你肯定要自己配置下cuda和cudnn，谷歌财大气粗，相当这些都帮你做好了。</div></div><img src ="http://www.cppblog.com/guijie/aggbug/216130.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guijie/" target="_blank">杰哥</a> 2018-12-21 09:07 <a href="http://www.cppblog.com/guijie/archive/2018/12/21/216130.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[zz] matplotlib.pyplot 中显示图像的两种模式（交互和阻塞）及其在Python画图中的应用</title><link>http://www.cppblog.com/guijie/archive/2018/12/17/216124.html</link><dc:creator>杰哥</dc:creator><author>杰哥</author><pubDate>Sun, 16 Dec 2018 22:10:00 GMT</pubDate><guid>http://www.cppblog.com/guijie/archive/2018/12/17/216124.html</guid><wfw:comment>http://www.cppblog.com/guijie/comments/216124.html</wfw:comment><comments>http://www.cppblog.com/guijie/archive/2018/12/17/216124.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guijie/comments/commentRss/216124.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guijie/services/trackbacks/216124.html</trackback:ping><description><![CDATA[<h2>介绍</h2><p style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px 0px 16px; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; overflow-wrap: break-word; font-family: -apple-system, &quot;SF UI Text&quot;, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif, SimHei, SimSun; background-color: #ffffff;">在使用matplotlib的过程中，发现不能像matlab一样同时开几个窗口进行比较，于是查询得知了交互模式，但是放在脚本里运行的适合却总是一闪而过，图像并不停留，遂仔细阅读和理解了一下文档，记下解决办法，问题比较简单，仅供菜鸟参考。</p><p style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px 0px 16px; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; overflow-wrap: break-word; font-family: -apple-system, &quot;SF UI Text&quot;, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif, SimHei, SimSun; background-color: #ffffff;">python可视化库matplotlib有两种显示模式：</p><ol style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px 0px 24px; list-style: none; overflow-wrap: break-word; color: #333333; font-family: -apple-system, &quot;SF UI Text&quot;, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif, SimHei, SimSun; background-color: #ffffff;"><li style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 8px 0px 0px 40px; list-style-type: decimal; overflow-wrap: break-word;">阻塞（block）模式</li><li style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 8px 0px 0px 40px; list-style-type: decimal; overflow-wrap: break-word;">交互（interactive）模式</li></ol><p style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px 0px 16px; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; overflow-wrap: break-word; font-family: -apple-system, &quot;SF UI Text&quot;, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif, SimHei, SimSun; background-color: #ffffff;">在Python Consol命令行中运行脚本，默认是阻塞模式。而在python IDE中运行脚本，matplotlib默认是交互模式。（使用python命令行运行脚本不能同时显示不同图像）</p><h2><a name="t1" style="box-sizing: border-box; outline: 0px; color: rgb(78, 161, 219); cursor: pointer; overflow-wrap: break-word;"></a>其中的区别是:</h2><p style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px 0px 16px; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; overflow-wrap: break-word; font-family: -apple-system, &quot;SF UI Text&quot;, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif, SimHei, SimSun; background-color: #ffffff;">在交互模式下：</p><ul style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px 0px 24px; list-style: none; overflow-wrap: break-word; color: #333333; font-family: -apple-system, &quot;SF UI Text&quot;, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif, SimHei, SimSun; background-color: #ffffff;"><li style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 8px 0px 0px 32px; list-style-type: disc; overflow-wrap: break-word;">plt.plot(x)或plt.imshow(x)是直接出图像，不需要plt.show()</li><li style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 8px 0px 0px 32px; list-style-type: disc; overflow-wrap: break-word;">如果在脚本中使用ion()命令开启了交互模式，没有使用ioff()关闭的话，则图像会一闪而过，并不会常留。要想防止这种情况，需要在plt.show()之前加上ioff()命令或者使用<span style="box-sizing: border-box; outline: 0px; font-weight: 700; overflow-wrap: break-word;">plt.pause(seconds)延长显示</span>。</li></ul><p style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px 0px 16px; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; overflow-wrap: break-word; font-family: -apple-system, &quot;SF UI Text&quot;, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif, SimHei, SimSun; background-color: #ffffff;">在阻塞模式下：</p><ul style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px 0px 24px; list-style: none; overflow-wrap: break-word; color: #333333; font-family: -apple-system, &quot;SF UI Text&quot;, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif, SimHei, SimSun; background-color: #ffffff;"><li style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 8px 0px 0px 32px; list-style-type: disc; overflow-wrap: break-word;">打开一个窗口以后必须关掉才能打开下一个新的窗口。这种情况下，默认是不能像Matlab一样同时开很多窗口进行对比的。</li><li style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 8px 0px 0px 32px; list-style-type: disc; overflow-wrap: break-word;">plt.plot(x)或plt.imshow(x)是直接出图像，需要plt.show()后才能显示图像</li></ul><h2><a name="t2" style="box-sizing: border-box; outline: 0px; color: rgb(78, 161, 219); cursor: pointer; overflow-wrap: break-word;"></a>示例</h2><p style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px 0px 16px; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; overflow-wrap: break-word; font-family: -apple-system, &quot;SF UI Text&quot;, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif, SimHei, SimSun; background-color: #ffffff;">下面这个例子讲的是如何像matlab一样同时打开多个窗口显示图片或线条进行比较，同时也是在脚本中开启交互模式后图像一闪而过的解决办法：</p><pre name="code" style="box-sizing: border-box; outline: 0px; padding: 8px; margin-top: 0px; margin-bottom: 24px; position: relative; white-space: pre-wrap; overflow-wrap: break-word; overflow-x: auto; font-family: Consolas, Inconsolata, Courier, monospace; line-height: 22px; background-color: #ffffff;"><code hljs"="" style="box-sizing: border-box; outline: 0px; display: block; overflow-x: auto; padding: 8px; color: #abb2bf; background: #282c34; border-radius: 4px; line-height: 22px; white-space: pre; overflow-wrap: break-word; font-family: &quot;Source Code Pro&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Ubuntu Mono&quot;, &quot;Anonymous Pro&quot;, &quot;Droid Sans Mono&quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, sans-serif;"><ol style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px; list-style: none; border-collapse: collapse; overflow: hidden; overflow-wrap: break-word;"><li style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px; list-style-type: none; overflow-wrap: break-word; height: 22px;"><div style="box-sizing: border-box; outline: 0px; margin: 0px; overflow-wrap: break-word; float: left; height: 22px; width: 24px; border-right: 1px solid #c5c5c5;"><div hljs-ln-n"="" data-line-number="1" style="box-sizing: border-box; outline: 0px; padding-right: 8px; margin: 0px; text-align: right; overflow-wrap: normal;"></div></div><div style="box-sizing: border-box; outline: 0px; margin: 0px 0px 0px 8px; overflow-wrap: break-word; float: left; height: 22px;"><div style="box-sizing: border-box; outline: 0px; margin: 0px; overflow-wrap: break-word;">    <span style="box-sizing: border-box; outline: 0px; color: #c678dd; overflow-wrap: break-word;">import</span> matplotlib.pyplot <span style="box-sizing: border-box; outline: 0px; color: #c678dd; overflow-wrap: break-word;">as</span> plt</div></div></li><li style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px; list-style-type: none; overflow-wrap: break-word; height: 22px;"><div style="box-sizing: border-box; outline: 0px; margin: 0px; overflow-wrap: break-word; float: left; height: 22px; width: 24px; border-right: 1px solid #c5c5c5;"><div hljs-ln-n"="" data-line-number="2" style="box-sizing: border-box; outline: 0px; padding-right: 8px; margin: 0px; text-align: right; overflow-wrap: normal;"></div></div><div style="box-sizing: border-box; outline: 0px; margin: 0px 0px 0px 8px; overflow-wrap: break-word; float: left; height: 22px;"><div style="box-sizing: border-box; outline: 0px; margin: 0px; overflow-wrap: break-word;">    plt.ion()    <span style="box-sizing: border-box; outline: 0px; color: #5c6370; font-style: italic; overflow-wrap: break-word;"># 打开交互模式</span></div></div></li><li style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px; list-style-type: none; overflow-wrap: break-word; height: 22px;"><div style="box-sizing: border-box; outline: 0px; margin: 0px; overflow-wrap: break-word; float: left; height: 22px; width: 24px; border-right: 1px solid #c5c5c5;"><div hljs-ln-n"="" data-line-number="3" style="box-sizing: border-box; outline: 0px; padding-right: 8px; margin: 0px; text-align: right; overflow-wrap: normal;"></div></div><div style="box-sizing: border-box; outline: 0px; margin: 0px 0px 0px 8px; overflow-wrap: break-word; float: left; height: 22px;"><div style="box-sizing: border-box; outline: 0px; margin: 0px; overflow-wrap: break-word;">    <span style="box-sizing: border-box; outline: 0px; color: #5c6370; font-style: italic; overflow-wrap: break-word;"># 同时打开两个窗口显示图片</span></div></div></li><li style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px; list-style-type: none; overflow-wrap: break-word; height: 22px;"><div style="box-sizing: border-box; outline: 0px; margin: 0px; overflow-wrap: break-word; float: left; height: 22px; width: 24px; border-right: 1px solid #c5c5c5;"><div hljs-ln-n"="" data-line-number="4" style="box-sizing: border-box; outline: 0px; padding-right: 8px; margin: 0px; text-align: right; overflow-wrap: normal;"></div></div><div style="box-sizing: border-box; outline: 0px; margin: 0px 0px 0px 8px; overflow-wrap: break-word; float: left; height: 22px;"><div style="box-sizing: border-box; outline: 0px; margin: 0px; overflow-wrap: break-word;">    plt.figure()</div></div></li><li style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px; list-style-type: none; overflow-wrap: break-word; height: 22px;"><div style="box-sizing: border-box; outline: 0px; margin: 0px; overflow-wrap: break-word; float: left; height: 22px; width: 24px; border-right: 1px solid #c5c5c5;"><div hljs-ln-n"="" data-line-number="5" style="box-sizing: border-box; outline: 0px; padding-right: 8px; margin: 0px; text-align: right; overflow-wrap: normal;"></div></div><div style="box-sizing: border-box; outline: 0px; margin: 0px 0px 0px 8px; overflow-wrap: break-word; float: left; height: 22px;"><div style="box-sizing: border-box; outline: 0px; margin: 0px; overflow-wrap: break-word;">    plt.imshow(i1)</div></div></li><li style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px; list-style-type: none; overflow-wrap: break-word; height: 22px;"><div style="box-sizing: border-box; outline: 0px; margin: 0px; overflow-wrap: break-word; float: left; height: 22px; width: 24px; border-right: 1px solid #c5c5c5;"><div hljs-ln-n"="" data-line-number="6" style="box-sizing: border-box; outline: 0px; padding-right: 8px; margin: 0px; text-align: right; overflow-wrap: normal;"></div></div><div style="box-sizing: border-box; outline: 0px; margin: 0px 0px 0px 8px; overflow-wrap: break-word; float: left; height: 22px;"><div style="box-sizing: border-box; outline: 0px; margin: 0px; overflow-wrap: break-word;">    plt.figure()</div></div></li><li style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px; list-style-type: none; overflow-wrap: break-word; height: 22px;"><div style="box-sizing: border-box; outline: 0px; margin: 0px; overflow-wrap: break-word; float: left; height: 22px; width: 24px; border-right: 1px solid #c5c5c5;"><div hljs-ln-n"="" data-line-number="7" style="box-sizing: border-box; outline: 0px; padding-right: 8px; margin: 0px; text-align: right; overflow-wrap: normal;"></div></div><div style="box-sizing: border-box; outline: 0px; margin: 0px 0px 0px 8px; overflow-wrap: break-word; float: left; height: 22px;"><div style="box-sizing: border-box; outline: 0px; margin: 0px; overflow-wrap: break-word;">    plt.imshow(i2)</div></div></li><li style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px; list-style-type: none; overflow-wrap: break-word; height: 22px;"><div style="box-sizing: border-box; outline: 0px; margin: 0px; overflow-wrap: break-word; float: left; height: 22px; width: 24px; border-right: 1px solid #c5c5c5;"><div hljs-ln-n"="" data-line-number="8" style="box-sizing: border-box; outline: 0px; padding-right: 8px; margin: 0px; text-align: right; overflow-wrap: normal;"></div></div><div style="box-sizing: border-box; outline: 0px; margin: 0px 0px 0px 8px; overflow-wrap: break-word; float: left; height: 22px;"><div style="box-sizing: border-box; outline: 0px; margin: 0px; overflow-wrap: break-word;">    <span style="box-sizing: border-box; outline: 0px; color: #5c6370; font-style: italic; overflow-wrap: break-word;"># 显示前关掉交互模式</span></div></div></li><li style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px; list-style-type: none; overflow-wrap: break-word; height: 22px;"><div style="box-sizing: border-box; outline: 0px; margin: 0px; overflow-wrap: break-word; float: left; height: 22px; width: 24px; border-right: 1px solid #c5c5c5;"><div hljs-ln-n"="" data-line-number="9" style="box-sizing: border-box; outline: 0px; padding-right: 8px; margin: 0px; text-align: right; overflow-wrap: normal;"></div></div><div style="box-sizing: border-box; outline: 0px; margin: 0px 0px 0px 8px; overflow-wrap: break-word; float: left; height: 22px;"><div style="box-sizing: border-box; outline: 0px; margin: 0px; overflow-wrap: break-word;">    plt.ioff()</div></div></li><li style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px; list-style-type: none; overflow-wrap: break-word; height: 22px;"><div style="box-sizing: border-box; outline: 0px; margin: 0px; overflow-wrap: break-word; float: left; height: 22px; width: 24px; border-right: 1px solid #c5c5c5;"><div hljs-ln-n"="" data-line-number="10" style="box-sizing: border-box; outline: 0px; padding-right: 8px; margin: 0px; text-align: right; overflow-wrap: normal;"></div></div><div style="box-sizing: border-box; outline: 0px; margin: 0px 0px 0px 8px; overflow-wrap: break-word; float: left; height: 22px;"><div style="box-sizing: border-box; outline: 0px; margin: 0px; overflow-wrap: break-word;">    plt.show()</div></div></li></ol></code><div data-title="复制" style="box-sizing: border-box; outline: 0px; padding: 2px 8px; margin: 8px; position: absolute; right: 4px; top: 4px; font-size: 12px; color: #4d4d4d; border-radius: 4px; cursor: pointer; box-shadow: rgba(0, 0, 0, 0.05) 0px 2px 4px, rgba(0, 0, 0, 0.05) 0px 2px 4px; overflow-wrap: break-word;"></div></pre><p style="box-sizing: border-box; outline: 0px; padding: 0px; margin: 0px 0px 16px; font-size: 16px; color: #4f4f4f; line-height: 26px; overflow-x: auto; overflow-wrap: break-word; font-family: -apple-system, &quot;SF UI Text&quot;, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif, SimHei, SimSun; background-color: #ffffff;">&nbsp;Reference:<br /><span style="font-family: verdana, &quot;courier new&quot;; font-size: 14px;">https://blog.csdn.net/wonengguwozai/article/details/79686062</span></p><img src ="http://www.cppblog.com/guijie/aggbug/216124.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guijie/" target="_blank">杰哥</a> 2018-12-17 06:10 <a href="http://www.cppblog.com/guijie/archive/2018/12/17/216124.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Error:Cannot start process, the path specified for working directory is not a directory</title><link>http://www.cppblog.com/guijie/archive/2018/11/05/216033.html</link><dc:creator>杰哥</dc:creator><author>杰哥</author><pubDate>Mon, 05 Nov 2018 01:59:00 GMT</pubDate><guid>http://www.cppblog.com/guijie/archive/2018/11/05/216033.html</guid><wfw:comment>http://www.cppblog.com/guijie/comments/216033.html</wfw:comment><comments>http://www.cppblog.com/guijie/archive/2018/11/05/216033.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guijie/comments/commentRss/216033.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guijie/services/trackbacks/216033.html</trackback:ping><description><![CDATA[<div>If I open one file such as "hw3_prob4Sol.py", the code can run. However, there is an error: Cannot start process, the path specified for working directory is not a directory. I can use the following method to solve this problem.<br />PyCharm change working directory of console</div><span style="color: #242729; font-family: Arial, &quot;Helvetica Neue&quot;, Helvetica, sans-serif; font-size: 15px; background-color: #ffffff;">Settings -&gt; Build Execution Deployment -&gt; Console -&gt; Python Console<br /><br />However, if I change the working directory every time, this gives me much trouble. Zhengxia is inspired by <br />"</span><span style="background-color: #ffffff; color: #242729; font-family: Arial, &quot;Helvetica Neue&quot;, Helvetica, sans-serif; font-size: 15px;">I finally solved the problem.</span><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-stretch: inherit; line-height: inherit; font-family: Arial, &quot;Helvetica Neue&quot;, Helvetica, sans-serif; font-size: 15px; vertical-align: baseline; box-sizing: inherit; clear: both; color: #242729; background-color: #ffffff;">I think it all started because the first project that I opened with pycharm was in my "download" folder, so the working directory was automatically set to a temporal folder by default and although I moved the project to another folder and I manually changed the working directory from the terminal, it was not working.</p><p style="margin: 0px 0px 1em; padding: 0px; border: 0px; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-stretch: inherit; line-height: inherit; font-family: Arial, &quot;Helvetica Neue&quot;, Helvetica, sans-serif; font-size: 15px; vertical-align: baseline; box-sizing: inherit; clear: both; color: #242729; background-color: #ffffff;">The solution was creating a new project and giving a correct path to the new project. It seems very easy but it was not that obvious." from&nbsp;<span style="font-family: verdana, &quot;courier new&quot;; font-size: 14px;">https://stackoverflow.com/questions/28202273/working-directory-error/28975990.<br /><br />He gave me the suggestion: File -&gt; open, open the directory rather than open the file. For example, "</span><span style="font-family: verdana, &quot;courier new&quot;; font-size: 14px;">GAN\code\generative-models-master", he said that it is better to make the environment of the&nbsp;pycharm&nbsp;projects consistent (pycharm工程默认加载一个环境变量,最好同一个工程下环境一致).&nbsp;</span><span style="font-family: verdana, &quot;courier new&quot;; font-size: 14px;">Then a file "</span><span style="font-family: verdana, &quot;courier new&quot;; font-size: 14px;">.idea</span><span style="font-family: verdana, &quot;courier new&quot;; font-size: 14px;">" will be created. In this way, all files of this folder will be seen as a part of this project. In the file&nbsp;</span><span style="font-family: verdana, &quot;courier new&quot;; font-size: 14px;">"</span><span style="font-family: verdana, &quot;courier new&quot;; font-size: 14px;">.idea</span><span style="font-family: verdana, &quot;courier new&quot;; font-size: 14px;">", there will be the historical record, the path setting such as the interpreter. Generally, we do not use this file.</span></p>Reference:<br /><div>https://stackoverflow.com/questions/37818938/pycharm-change-working-directory-of-console</div><img src ="http://www.cppblog.com/guijie/aggbug/216033.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guijie/" target="_blank">杰哥</a> 2018-11-05 09:59 <a href="http://www.cppblog.com/guijie/archive/2018/11/05/216033.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> PyCharm skills: indention</title><link>http://www.cppblog.com/guijie/archive/2018/10/14/216008.html</link><dc:creator>杰哥</dc:creator><author>杰哥</author><pubDate>Sat, 13 Oct 2018 21:08:00 GMT</pubDate><guid>http://www.cppblog.com/guijie/archive/2018/10/14/216008.html</guid><wfw:comment>http://www.cppblog.com/guijie/comments/216008.html</wfw:comment><comments>http://www.cppblog.com/guijie/archive/2018/10/14/216008.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guijie/comments/commentRss/216008.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guijie/services/trackbacks/216008.html</trackback:ping><description><![CDATA[Tab: Right indention<br /><span style="color: #4f4f4f; font-family: -apple-system, &quot;SF UI Text&quot;, Arial, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif, SimHei, SimSun; font-size: 16px; background-color: #ffffff;">Shift + Tab</span>: Left indention<br />Sui Li says that&nbsp;word, powerpoint and group wiki (foreseer) also use this.<img src ="http://www.cppblog.com/guijie/aggbug/216008.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guijie/" target="_blank">杰哥</a> 2018-10-14 05:08 <a href="http://www.cppblog.com/guijie/archive/2018/10/14/216008.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>How to read *.mat file in python?</title><link>http://www.cppblog.com/guijie/archive/2018/10/14/216007.html</link><dc:creator>杰哥</dc:creator><author>杰哥</author><pubDate>Sat, 13 Oct 2018 20:47:00 GMT</pubDate><guid>http://www.cppblog.com/guijie/archive/2018/10/14/216007.html</guid><wfw:comment>http://www.cppblog.com/guijie/comments/216007.html</wfw:comment><comments>http://www.cppblog.com/guijie/archive/2018/10/14/216007.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guijie/comments/commentRss/216007.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guijie/services/trackbacks/216007.html</trackback:ping><description><![CDATA[# See P4 of "HW2_545_2018_"<br />import scipy.io as sio<br /><div>mnist_49_3000 = sio.loadmat('mnist_49_3000.mat')</div><img src ="http://www.cppblog.com/guijie/aggbug/216007.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guijie/" target="_blank">杰哥</a> 2018-10-14 04:47 <a href="http://www.cppblog.com/guijie/archive/2018/10/14/216007.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>How to read *.data in Matlab and Python</title><link>http://www.cppblog.com/guijie/archive/2018/10/13/216005.html</link><dc:creator>杰哥</dc:creator><author>杰哥</author><pubDate>Fri, 12 Oct 2018 20:33:00 GMT</pubDate><guid>http://www.cppblog.com/guijie/archive/2018/10/13/216005.html</guid><wfw:comment>http://www.cppblog.com/guijie/comments/216005.html</wfw:comment><comments>http://www.cppblog.com/guijie/archive/2018/10/13/216005.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guijie/comments/commentRss/216005.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guijie/services/trackbacks/216005.html</trackback:ping><description><![CDATA[<div>See P2 of "HW2_545_2018_"<br /><br />In Matlab:</div><div>z = dlmread('spambase.data',',');</div><div>In Python:</div><div>import numpy as np</div><div>z = np.genfromtxt('spambase.data', dtype=float, delimiter=',')</div><div></div><img src ="http://www.cppblog.com/guijie/aggbug/216005.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guijie/" target="_blank">杰哥</a> 2018-10-13 04:33 <a href="http://www.cppblog.com/guijie/archive/2018/10/13/216005.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>product in python: np.dot, np.multiply, *</title><link>http://www.cppblog.com/guijie/archive/2018/10/06/215992.html</link><dc:creator>杰哥</dc:creator><author>杰哥</author><pubDate>Sat, 06 Oct 2018 00:33:00 GMT</pubDate><guid>http://www.cppblog.com/guijie/archive/2018/10/06/215992.html</guid><wfw:comment>http://www.cppblog.com/guijie/comments/215992.html</wfw:comment><comments>http://www.cppblog.com/guijie/archive/2018/10/06/215992.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guijie/comments/commentRss/215992.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guijie/services/trackbacks/215992.html</trackback:ping><description><![CDATA[<div>https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.dot.html<br /><p style="margin: 0px 0px 9.5px; color: #333333; font-family: &quot;Open Sans&quot;, sans-serif; font-size: 13px; background-color: #ffffff;">Dot product of two arrays. Specifically,</p><ul style="padding: 0px; margin: 0px 0px 10px 25px; color: #333333; font-family: &quot;Open Sans&quot;, sans-serif; font-size: 13px; background-color: #ffffff;"><li style="line-height: 19px;"><p style="margin-top: 0px !important; margin-right: 0px; margin-bottom: 9.5px; margin-left: 0px;">If both&nbsp;<em py=""  py-obj"="">a</em>&nbsp;and&nbsp;<em py=""  py-obj"="">b</em>&nbsp;are 1-D arrays, it is inner product of vectors (without complex conjugation).</p></li><li style="line-height: 19px;"><p style="margin-top: 0px !important; margin-right: 0px; margin-bottom: 9.5px; margin-left: 0px;"><span style="color: red;">If both&nbsp;</span><em py=""  py-obj"="" style="color: red;">a</em><span style="color: red;">&nbsp;and&nbsp;</span><em py=""  py-obj"="" style="color: red;">b</em><span style="color: red;">&nbsp;are 2-D arrays, it is matrix multiplication, but </span>using&nbsp;<a internal"="" href="https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.matmul.html#numpy.matmul" title="numpy.matmul" style="color: red; text-decoration-line: none;"><code py="" py-func="" docutils=""  literal"="" style="padding-top: inherit; padding-right: inherit; padding-bottom: inherit; padding-left: 0px; font-family: inherit; font-size: inherit; color: inherit; border-radius: 3px; background-color: inherit; border: none; white-space: nowrap; font-style: inherit; font-variant: inherit; font-weight: bold; font-stretch: inherit; line-height: inherit;"><span style="hyphens: none;">matmul</span></code></a>&nbsp;or&nbsp;<code literal"="" style="padding-top: inherit; padding-right: inherit; padding-bottom: inherit; padding-left: 2px; font-size: inherit; color: red; border-radius: 3px; background-color: #f2f2f2; border: inherit; white-space: nowrap; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit;"><span style="hyphens: none;">a</span>&nbsp;<span style="hyphens: none;">@</span>&nbsp;<span style="hyphens: none;">b</span></code>&nbsp;is<span style="color: red;"> preferred.</span></p></li><li style="line-height: 19px;"><p style="margin-top: 0px !important; margin-right: 0px; margin-bottom: 9.5px; margin-left: 0px;"><span style="color: red;">If either&nbsp;</span><em py=""  py-obj"="" style="color: red;">a</em><span style="color: red;">&nbsp;or&nbsp;</span><em py=""  py-obj"="" style="color: red;">b</em><span style="color: red;">&nbsp;is 0-D (scalar), it is equivalent </span>to&nbsp;<a internal"="" href="https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.multiply.html#numpy.multiply" title="numpy.multiply" style="color: red; text-decoration-line: none;"><code py="" py-func="" docutils=""  literal"="" style="padding-top: inherit; padding-right: inherit; padding-bottom: inherit; padding-left: 0px; font-family: inherit; font-size: inherit; color: inherit; border-radius: 3px; background-color: inherit; border: none; white-space: nowrap; font-style: inherit; font-variant: inherit; font-weight: bold; font-stretch: inherit; line-height: inherit;"><span style="hyphens: none;">multiply</span></code></a>&nbsp;and<span style="color: red;"> </span>using&nbsp;<code literal"="" style="padding-top: inherit; padding-right: inherit; padding-bottom: inherit; padding-left: 2px; font-size: inherit; color: red; border-radius: 3px; background-color: #f2f2f2; border: inherit; white-space: nowrap; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit;"><span style="hyphens: none;">numpy.multiply(a,</span>&nbsp;<span style="hyphens: none;">b)</span></code>&nbsp;or&nbsp;<code literal"="" style="padding-top: inherit; padding-right: inherit; padding-bottom: inherit; padding-left: 2px; font-size: inherit; color: red; border-radius: 3px; background-color: #f2f2f2; border: inherit; white-space: nowrap; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit;"><span style="hyphens: none;">a</span>&nbsp;<span style="hyphens: none;">*</span>&nbsp;<span style="hyphens: none;">b</span></code>&nbsp;is<span style="color: red;"> preferred.</span></p></li><li style="line-height: 19px;"><p style="margin-top: 0px !important; margin-right: 0px; margin-bottom: 9.5px; margin-left: 0px;">If&nbsp;<em py=""  py-obj"="">a</em>&nbsp;is an N-D array and&nbsp;<em py=""  py-obj"="">b</em>&nbsp;is a 1-D array, it is a sum product over the last axis of&nbsp;<em py=""  py-obj"="">a</em>&nbsp;and&nbsp;<em py=""  py-obj"="">b</em>.</p></li><li style="line-height: 19px;"><p style="margin-top: 0px !important; margin-right: 0px; margin-bottom: 9.5px; margin-left: 0px;">If&nbsp;<em py=""  py-obj"="">a</em>&nbsp;is an N-D array and&nbsp;<em py=""  py-obj"="">b</em>&nbsp;is an M-D array (where&nbsp;<code literal"="" style="padding-top: inherit; padding-right: inherit; padding-bottom: inherit; padding-left: 2px; font-size: inherit; color: inherit; border-radius: 3px; background-color: #f2f2f2; border: inherit; white-space: nowrap; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit;"><span style="hyphens: none;">M&gt;=2</span></code>), it is a sum product over the last axis of&nbsp;<em py=""  py-obj"="">a</em>&nbsp;and the second-to-last axis of&nbsp;<em py=""  py-obj"="">b</em>:</p><div style="position: relative;"><div style="background: #eeffcc;"><pre style="padding: 9px; font-size: 12px; border-radius: 0px; margin-top: 0px; margin-bottom: 9.5px; line-height: 19px; word-break: break-all; overflow-wrap: break-word; white-space: pre-wrap; background-color: #f5f5f5; border: none; overflow: auto hidden;">dot(a, b)[i,j,k,m] <span style="color: #666666;">=</span> <span style="color: #007020;">sum</span>(a[i,j,:] <span style="color: #666666;">*</span> b[k,:,m])</pre></div></div></li></ul></div><font color="#ff0000">What does the last two points mean?<br /></font>My understanding is that 2-D arrays are a matrix. N-D array is a tensor. The aforementioned example is very clear. Both a and b are 3-D arrays.<img src ="http://www.cppblog.com/guijie/aggbug/215992.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guijie/" target="_blank">杰哥</a> 2018-10-06 08:33 <a href="http://www.cppblog.com/guijie/archive/2018/10/06/215992.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Interpreter of Pycharm</title><link>http://www.cppblog.com/guijie/archive/2018/10/05/215990.html</link><dc:creator>杰哥</dc:creator><author>杰哥</author><pubDate>Fri, 05 Oct 2018 00:59:00 GMT</pubDate><guid>http://www.cppblog.com/guijie/archive/2018/10/05/215990.html</guid><wfw:comment>http://www.cppblog.com/guijie/comments/215990.html</wfw:comment><comments>http://www.cppblog.com/guijie/archive/2018/10/05/215990.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guijie/comments/commentRss/215990.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guijie/services/trackbacks/215990.html</trackback:ping><description><![CDATA[<div>Yang Zhou says that there can be infinity python.exe in your computer. Maybe some install numpy while some not.</div><div>Some other interpreters on my computer:&nbsp;</div><div>C:\Users\think\PycharmProjects\Test\venv\Scripts\python.exe&nbsp; &nbsp; &nbsp; &nbsp;Even if I reinstall my operating system, the files in C:\Users\think\PycharmProjects do not need to be stored since this in an empty project.</div><div>E:\OneDrive - ustc.edu\PycharmProjects\Test\venv\Scripts</div><div>I have set C:\Users\think\Anaconda3\python.exe as the default interpreter. This interpreter has installed numpy. How can we set this? pycharm -&gt; File -&gt; Default settings</div><div>pycharm -&gt; File -&gt; settings -&gt; show all -&gt; existing environment</div><div><span style="color: red;">One interesting fact is that if I name a directory as _numpy and "import </span><span style="color: red;">numpy</span><span style="color: red;"> as np" will have </span><span style="color: red;">error</span><span style="color: red;">. This error can be solved by changing the name of the directory from _numpy to _numpy1.</span><br /><br />Reference:<br /><div>https://blog.csdn.net/chengzihe_lu/article/details/79639804</div></div><p align="left"><span lang="EN-US" style="font-size: 12pt; font-family: &quot;Times New Roman&quot;, serif;"></span></p><p align="left"><span style="font-size:12.0pt;font-family:&quot;Times New Roman&quot;,&quot;serif&quot;;Times New Roman&quot;;"><br /></span></p><img src ="http://www.cppblog.com/guijie/aggbug/215990.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guijie/" target="_blank">杰哥</a> 2018-10-05 08:59 <a href="http://www.cppblog.com/guijie/archive/2018/10/05/215990.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>pycharm 默认布局乱了</title><link>http://www.cppblog.com/guijie/archive/2018/08/28/215883.html</link><dc:creator>杰哥</dc:creator><author>杰哥</author><pubDate>Mon, 27 Aug 2018 21:26:00 GMT</pubDate><guid>http://www.cppblog.com/guijie/archive/2018/08/28/215883.html</guid><wfw:comment>http://www.cppblog.com/guijie/comments/215883.html</wfw:comment><comments>http://www.cppblog.com/guijie/archive/2018/08/28/215883.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guijie/comments/commentRss/215883.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guijie/services/trackbacks/215883.html</trackback:ping><description><![CDATA[根据https://python.freelycode.com/article/detail/736/解决方案:&nbsp;<span style="color: #333333; font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; background-color: #f9f9f9;">菜单&nbsp; Window&gt;restore default layout。但是我的菜单栏没有window。乱点，菜单栏下面一行右键，有Customize Menus and Toolbars， Restore All Defaults。菜单栏就有了Window</span><img src ="http://www.cppblog.com/guijie/aggbug/215883.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guijie/" target="_blank">杰哥</a> 2018-08-28 05:26 <a href="http://www.cppblog.com/guijie/archive/2018/08/28/215883.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>matlab errorbar</title><link>http://www.cppblog.com/guijie/archive/2012/09/06/189645.html</link><dc:creator>杰哥</dc:creator><author>杰哥</author><pubDate>Thu, 06 Sep 2012 01:28:00 GMT</pubDate><guid>http://www.cppblog.com/guijie/archive/2012/09/06/189645.html</guid><wfw:comment>http://www.cppblog.com/guijie/comments/189645.html</wfw:comment><comments>http://www.cppblog.com/guijie/archive/2012/09/06/189645.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guijie/comments/commentRss/189645.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guijie/services/trackbacks/189645.html</trackback:ping><description><![CDATA[<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; background-color: #bababa; list-style-type: none; margin-top: 0px; padding-left: 0px; padding-right: 0px; font-family: simsun; word-wrap: normal; color: #084487; margin-left: 0px; word-break: normal; border-top: 0px; margin-right: 0px; border-right: 0px; padding-top: 0px"></p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; list-style-type: none; margin-top: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; margin-left: 0px; word-break: normal; border-top: 0px; margin-right: 0px; border-right: 0px; padding-top: 0px">On the group meeting of Oct 3, 2018, Jiaqi shows his bar. I asked that why his variance is very small. He said that he uses the&nbsp;standard error (https://en.wikipedia.org/wiki/Standard_error), which is standard derivation divided by the square root of the number of trials. According to the notes of my undergraduate course probability:<br />(1) D(ax+b) = a*a*D(x),<br />(2) the second line of "中心极限定理". x bar is seen as a random variable,<br />we have std(x bar) = std(x)/sqrt(n).<br />I ask Jiaqi which tool he uses to draw his figure. He says he uses python, bar of matplotlib. https://matplotlib.org/api/_as_gen/matplotlib.pyplot.bar.html. The mean of the errors and&nbsp;standard error should be computed first and then be used as the input of xerr and yerr.&nbsp;<br />I check&nbsp;my&nbsp;TNNLS 2017 paper and I find that I show the std. Maybe next time I can show the&nbsp;standard error.</p><p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; list-style-type: none; margin-top: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; margin-left: 0px; word-break: normal; border-top: 0px; margin-right: 0px; border-right: 0px; padding-top: 0px"><br /></p><p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; list-style-type: none; margin-top: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; margin-left: 0px; word-break: normal; border-top: 0px; margin-right: 0px; border-right: 0px; padding-top: 0px">这个函数的意思是：<br />ERRORBAR(X,Y,L,U)，X是自变量，Y是因变量，L是Y的变动下限，U是Y的变动上限</p>
<p style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; list-style-type: none; margin-top: 0px; padding-left: 0px; padding-right: 0px; word-wrap: normal; margin-left: 0px; word-break: normal; border-top: 0px; margin-right: 0px; border-right: 0px; padding-top: 0px">errorbar(X,Y,E)&nbsp;<wbr>&nbsp;X是自变量，Y是因变量，E是Y的变动绝对差值。</p><span style="color: red">我自己写的例子：<br /></span>
<div>&nbsp;X=[1 2 3];</div>
<div>Y= [ 0.2 0.4 0.2];</div>
<div>L=[0.1 0.03 0.03];U=[0.1 0.3 0.2];</div>
<div>E= [0.1 0.3 0.2];<br />
<div>figure;</div>
<div>hold on;%一定要有这一句，否则有问题</div>
<div>bar(X,Y);</div>
<div>errorbar(X,Y,E,'Marker','none','LineStyle','none');<br />
<div>figure;</div>
<div>hold on;%一定要有这一句，否则有问题</div>
<div>errorbar(X,Y,E);%以下注释的两句用这一句就可以了<br />%plot(X,Y);</div>
<div>%errorbar(X,Y,E,'Marker','none','LineStyle','none');</div></div></div>
<div>figure;</div>
<div>hold on;%一定要有这一句，否则有问题</div>
<div>bar(X,Y);</div>
<div>errorbar(X,Y,L,U);%,'Marker','none','LineStyle','none'不能省</div>
<div></div><span style="color: red">说明：必须使用hold on，bar是画柱状图，</span><span style="color: red"> errorbar是花竖线</span><br /><span style="color: red">--------------------------------------------------------------------以下可不看----------------------------------------------------------------------------<br />example1：</span>
<p>&nbsp;</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; background-color: #bababa; list-style-type: none; margin-top: 0px; padding-left: 0px; padding-right: 0px; font-family: simsun; word-wrap: normal; color: #084487; margin-left: 0px; word-break: normal; border-top: 0px; margin-right: 0px; border-right: 0px; padding-top: 0px">&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;x = 1:10;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;y = sin(x);<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;e = std(y)*ones(size(x));<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;errorbar(x,y,e)</p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; background-color: #bababa; list-style-type: none; margin-top: 0px; padding-left: 0px; padding-right: 0px; font-family: simsun; word-wrap: normal; color: #084487; margin-left: 0px; word-break: normal; border-top: 0px; margin-right: 0px; border-right: 0px; padding-top: 0px">&nbsp;<wbr></p>
<p style="border-bottom: 0px; text-align: left; border-left: 0px; padding-bottom: 0px; background-color: #bababa; list-style-type: none; margin-top: 0px; padding-left: 0px; padding-right: 0px; font-family: simsun; word-wrap: normal; color: #084487; margin-left: 0px; word-break: normal; border-top: 0px; margin-right: 0px; border-right: 0px; padding-top: 0px"><a style="color: #084487" href="http://photo.blog.sina.com.cn/showpic.html#blogid=61010ebe0100l9c9&amp;url=http://s16.sinaimg.cn/orignal/61010ebex8f868702afcf" target="_blank"><img style="border-bottom: 0px; border-left: 0px; padding-bottom: 0px; list-style-type: none; margin: 0px; padding-left: 0px; padding-right: 0px; border-top: 0px; border-right: 0px; padding-top: 0px" title="matlab的errorbar函数" name="image_operate_14791283707871486" alt="matlab的errorbar函数" src="http://s16.sinaimg.cn/middle/61010ebex8f868702afcf&amp;690" width="561" height="420" action-type="show-slide" action-data="http%3A%2F%2Fs16.sinaimg.cn%2Fmiddle%2F61010ebex8f868702afcf%26690" real_src="http://s16.sinaimg.cn/middle/61010ebex8f868702afcf&amp;690" /></a></p><span style="text-align: left; background-color: #bababa; font-family: simsun; color: #ff0000">example2：</span>&nbsp;<br /><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; font-style: italic; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #406040; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">% 生成示例数据</span><br style="text-align: left; line-height: 18px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px" /><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">x=</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #0080a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">1</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">:</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #0080a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">10</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">;</span><br style="text-align: left; line-height: 18px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px" /><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">y=</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #2060a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">cumsum</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">(</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #2060a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">randn</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">(</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #0080a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">1</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">,</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #0080a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">10</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">)</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">)</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">;</span><br style="text-align: left; line-height: 18px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px" /><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #2060a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">lower</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">&nbsp;= y -&nbsp;</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">(</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #2060a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">rand</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">(</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #0080a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">1</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">,</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #0080a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">10</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">)</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">)</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">;</span><br style="text-align: left; line-height: 18px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px" /><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #2060a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">upper</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">&nbsp;= y +&nbsp;</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">(</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #2060a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">rand</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">(</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #0080a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">1</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">,</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #0080a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">10</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">)</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">)</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">;</span><br style="text-align: left; line-height: 18px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px" /><br style="text-align: left; line-height: 18px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px" /><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; font-style: italic; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #406040; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">% 由于errorbar函数使用相对差值在图形上绘图，所以</span><br style="text-align: left; line-height: 18px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px" /><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; font-style: italic; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #406040; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">% 需要将绝对差值转变为相对差值。</span><br style="text-align: left; line-height: 18px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px" /><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">L = y -&nbsp;</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #2060a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">lower</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">;</span><br style="text-align: left; line-height: 18px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px" /><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">U =&nbsp;</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #2060a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">upper</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">&nbsp;-y;</span><br style="text-align: left; line-height: 18px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px" /><br style="text-align: left; line-height: 18px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px" /><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; font-style: italic; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #406040; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">% 绘图时需要设定 hold on</span><br style="text-align: left; line-height: 18px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px" /><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; font-style: italic; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #406040; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">% 柱状图</span><br style="text-align: left; line-height: 18px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px" /><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #2060a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">clf</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">;</span><br style="text-align: left; line-height: 18px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px" /><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #2060a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">figure</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">(</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #0080a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">1</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">)</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">;</span><br style="text-align: left; line-height: 18px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px" /><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #2060a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">hold</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">&nbsp;on;</span><br style="text-align: left; line-height: 18px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px" /><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #2060a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">bar</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">(</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">x,y</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">)</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">;</span><br style="text-align: left; line-height: 18px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px" /><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; font-style: italic; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #406040; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">% 此处需要隐藏折线</span><br style="text-align: left; line-height: 18px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px" /><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #2060a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">errorbar</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">(</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">x,y,L,U,</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; font-style: italic; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #406040; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">'Marker'</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">,</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; font-style: italic; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #406040; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">'none'</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">,</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; font-style: italic; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #406040; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">'LineStyle'</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">,</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; font-style: italic; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #406040; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">'none'</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">)</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">;</span><br style="text-align: left; line-height: 18px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px" /><br style="text-align: left; line-height: 18px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px" /><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; font-style: italic; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #406040; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">% 折线图</span><br style="text-align: left; line-height: 18px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px" /><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #2060a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">figure</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">(</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #0080a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">2</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">)</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">;</span><br style="text-align: left; line-height: 18px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px" /><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #2060a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">hold</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">(</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; font-style: italic; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #406040; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">'on'</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">)</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">;</span><br style="text-align: left; line-height: 18px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px" /><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #2060a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">plot</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">(</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">&nbsp;x, y</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">)</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">;</span><br style="text-align: left; line-height: 18px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px" /><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; color: #2060a0; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">errorbar</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">(</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">&nbsp;x, y, L, U</span><span style="border-bottom: medium none; text-align: left; border-left: medium none; padding-bottom: 0px; line-height: 18px; margin: 0px; outline-style: none; outline-color: invert; padding-left: 0px; outline-width: medium; padding-right: 0px; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px; vertical-align: baseline; border-top: medium none; border-right: medium none; padding-top: 0px">)</span><span style="text-align: left; line-height: 18px; background-color: #f1f1f1; font-family: Monaco, 'Lucida Console', monospace; white-space: nowrap; font-size: 13px">;</span>&nbsp;<br /><br />Reference:<br /><a href="http://blog.sina.com.cn/s/blog_61010ebe0100l9c9.html">http://blog.sina.com.cn/s/blog_61010ebe0100l9c9.html</a>&nbsp;<br /><a href="http://bio-spring.info/wp/?p=85">http://bio-spring.info/wp/?p=85</a>&nbsp;<img src ="http://www.cppblog.com/guijie/aggbug/189645.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guijie/" target="_blank">杰哥</a> 2012-09-06 09:28 <a href="http://www.cppblog.com/guijie/archive/2012/09/06/189645.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Python path; matlab function load, save</title><link>http://www.cppblog.com/guijie/archive/2012/06/20/179529.html</link><dc:creator>杰哥</dc:creator><author>杰哥</author><pubDate>Wed, 20 Jun 2012 13:07:00 GMT</pubDate><guid>http://www.cppblog.com/guijie/archive/2012/06/20/179529.html</guid><wfw:comment>http://www.cppblog.com/guijie/comments/179529.html</wfw:comment><comments>http://www.cppblog.com/guijie/archive/2012/06/20/179529.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/guijie/comments/commentRss/179529.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/guijie/services/trackbacks/179529.html</trackback:ping><description><![CDATA[<div style="text-align: center; "><span style="color: red;">matlab函数load 目录，save</span></div>目录都用反斜杠，这样windows和Linux目录都认，Linux只认反斜杠&nbsp;<br /><span style="color: red; ">当前目录：</span><br /><div>for s=1:20</div><div>&nbsp; &nbsp; filename = num2str(s);</div><div>&nbsp; &nbsp; load (filename);<br />end</div><div></div><span style="color: red; ">当前目录</span><span style="color: #ff0000;">的下一层目录</span><span style="color: red; ">：</span><br /><div></div><div></div><div>for s=1:20<br />&nbsp; &nbsp;&nbsp;%filename = ['./50Train/',num2str(s),'.mat']; &nbsp;%<span style="color: red; ">这种方式应该更快，省得字符串操作<br /></span>&nbsp; &nbsp;&nbsp;%filename = ['50Train/',num2str(s)]; &nbsp; &nbsp;%<span style="color: red; ">最前面的./不加也可以</span><br /><div>&nbsp; &nbsp; %filename = ['./50Train/',num2str(s)];</div><div>&nbsp; &nbsp; filename = strcat('./50Train/',num2str(s));</div></div><div>&nbsp; &nbsp; load (filename);<br />end</div><div></div><div></div><span style="color: red; ">当前目录的上一层目录：</span><br /><div>for s=1:20<br />&nbsp; &nbsp;&nbsp;%filename = ['../50Train/',num2str(s),'.mat'];&nbsp;<br /><div>&nbsp; &nbsp; %filename = ['../50Train/',num2str(s)];</div><div>&nbsp; &nbsp; filename = strcat('../50Train/',num2str(s));</div></div><div>&nbsp; &nbsp; load (filename);<br />end<br /><br /><div>dataName = '../Parmprint.mat';%<span style="color: red;">'..</span><span style="color: red;">/</span><span style="color: red;">Parmprint</span><span style="color: red;">/</span><span style="color: red;">'和</span><span style="color: red;">Parmprint.mat/'都不行</span></div>例：caffe-master-20151202\caffe-master\matlab\demo\classification_demo.m, &nbsp;im = imread('../../examples/images/cat.jpg');<br />----------------------------------------------------------------------<br /><div>&nbsp; <span style="color: red; ">想编一个循环，每个文件名依次是1，2，等到num</span><br />for i =1:num<br />&nbsp; &nbsp; savefile = [num2str(i),'.mat'];</div><div>&nbsp; &nbsp; save(savefile, 'trainIdx', 'testIdx');%trainIdx 和testIdx 可以是其他任何变量<br />end<br /><br /><span style="color: red;">save的名字中含有小数点</span><br />ratio = 0.01;<br /><div>savefile = ['NFL_ASLAN',num2str(ratio),'.mat'];</div><div>save(savefile, 'accuracy');</div><span style="color: #ff0000; font-family: Verdana, Helvetica, Arial; font-size: 13px; line-height: 18px; text-align: justify; background-color: #ffffff; ">见我的matlab教材P20</span>&nbsp;<br /><br /><br /><div style="text-align: center;"><font color="#ff0000">Python path</font><br /><div style="text-align: left;"><span style="text-align: center;">If I put Homework2Q2.py in another content(目录) and I use the&nbsp;</span><span style="background-color: #ffffff; font-family: 微软雅黑; font-size: 9pt; text-align: center;">"</span><span style="font-family: 宋体; font-size: 9pt; color: #008080; font-weight: bold;">E:\OneDrive - ustc.edu\Lecture</span><span style="font-family: 宋体; font-size: 9pt; color: #008000; background-color: #ffcccc;">\ustc</span><span style="font-family: 宋体; font-size: 9pt; color: #008080; font-weight: bold;">\Artificial intelligence related\Machine learning</span><span style="font-family: 宋体; font-size: 9pt; color: #008000; background-color: #ffcccc;">\Umich</span><span style="font-family: 宋体; font-size: 9pt; color: #008080; font-weight: bold;">\</span><span style="font-family: 宋体; font-size: 9pt; color: #008080; font-weight: bold;">...</span><span style="background-color: #ffffff; font-family: 宋体; font-size: 9pt;">"</span><span style="text-align: center;">in line 4, there is an error as follows:<br /></span><span style="text-align: center;">SyntaxError: (</span>unicode<span style="text-align: center;"> error) '</span>unicodeescape<span style="text-align: center;">' codec can't decode bytes in position 30-31: truncated \uXXXX escape</span></div><div style="text-align: left;">Zhou Yang says that in Python '\n' has a specific meaning. Similarly, python will think '\u' and '\U' has a specific meaning. Write '\\u' and '\\U' instead. Zhengxia says that there are two other ways to solve this problem:<br />(1) r'<span style="font-family: 宋体; font-size: 9pt; color: #008080; font-weight: bold;">E:\OneDrive - ustc.edu\Lecture</span><span style="font-family: 宋体; font-size: 9pt; color: #008000; background-color: #ffcccc;">\ustc</span><span style="font-family: 宋体; font-size: 9pt; color: #008080; font-weight: bold;">\Artificial intelligence related\Machine learning</span><span style="font-family: 宋体; font-size: 9pt; color: #008000; background-color: #ffcccc;">\Umich</span><span style="font-family: 宋体; font-size: 9pt; color: #008080; font-weight: bold;">\</span><span style="font-family: 宋体; font-size: 9pt; color: #008080; font-weight: bold;">...</span>'<br />(2) use / rather than \</div><div style="text-align: left;"><font color="#ff0000"></font></div></div></div></div><img src ="http://www.cppblog.com/guijie/aggbug/179529.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/guijie/" target="_blank">杰哥</a> 2012-06-20 21:07 <a href="http://www.cppblog.com/guijie/archive/2012/06/20/179529.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>