??xml version="1.0" encoding="utf-8" standalone="yes"?>热久久最新网站获取,精品综合久久久久久98,国产一久久香蕉国产线看观看http://www.shnenglu.com/guijie/category/21368.html杰哥?哈哈!zh-cnSat, 05 Sep 2020 14:27:37 GMTSat, 05 Sep 2020 14:27:37 GMT60[zz] Python3中print()函数输出多个变量http://www.shnenglu.com/guijie/archive/2020/09/05/217438.html杰哥杰哥Sat, 05 Sep 2020 00:44:00 GMThttp://www.shnenglu.com/guijie/archive/2020/09/05/217438.htmlhttp://www.shnenglu.com/guijie/comments/217438.htmlhttp://www.shnenglu.com/guijie/archive/2020/09/05/217438.html#Feedback0http://www.shnenglu.com/guijie/comments/commentRss/217438.htmlhttp://www.shnenglu.com/guijie/services/trackbacks/217438.htmlW一U方法:(x)     print("变量1", file_name, "变量2", new_name)
print("变量1", file_name, "变量2", new_name) 

W二U方法:(x)     print("变量1Q?s 变量2Q?s" % (file_name, new_name))

print("变量1Q?s 变量2Q?s" % (file_name, new_name)) 

W三U方法:(x).format()  

print('变量1Q{0} 变量2Q{1}'.format(file_name, new_name))

  1. print('变量1Q{0} 变量2Q{1}'.format(file_name, new_name))
  2. # 需要注意的是,python是从0开始计敎ͼ所以第一个{}里要?开始,依次1?…

Reference:
https://blog.csdn.net/zhangvalue/article/details/103841029


杰哥 2020-09-05 08:44 发表评论
]]>
[zz] 3 个相见恨晚的 Google Colaboratory 奇技http://www.shnenglu.com/guijie/archive/2019/02/13/216240.html杰哥杰哥Wed, 13 Feb 2019 15:56:00 GMThttp://www.shnenglu.com/guijie/archive/2019/02/13/216240.htmlhttp://www.shnenglu.com/guijie/comments/216240.htmlhttp://www.shnenglu.com/guijie/archive/2019/02/13/216240.html#Feedback0http://www.shnenglu.com/guijie/comments/commentRss/216240.htmlhttp://www.shnenglu.com/guijie/services/trackbacks/216240.html原文出处Q?/span>

https://www.kdnuggets.com/2018/02/essential-google-colaboratory-tips-tricks.html


试想一下,如果有个免费的在U云端^収ͼ既可以不用安?TensorFlow 直接使用Q又可以实现 GPU 加速训l,那该是多好的一件事情。你没听错,q种好事实存在Q今天我重介l一个谷歌推出的免费的云端工P(x)Colaboratory?/span>


Colaboratory 是一?Google 研究目Q旨在帮助传播机器学?fn)培训和研究成果?/span>它是一?Jupyter W记本环?/span>Q不需要进行Q何设|就可以使用Qƈ且完全在云端q行。Colaboratory W记本存储在 Google 云端盘中,q且可以׃nQ就如同(zhn)?Google 文档或表g栗Colaboratory 可免费用?/span>


也就是说QColaboratory 存储?Google 云端盘中,我们可以?Google 云端盘里直接编?Jupyter NotebookQ在U用深度学?fn)框?TensorFlow q训l我们的经|络了。超炫!



q里?3 个o(h)人相见恨晚的奇技淫y来简化它的用,分别是:(x)使用免费?GPU、安装库、上传ƈ使用数据文g?/span>


下面分别介绍Q?/span>


1. 使用免费?GPU


在打开?Jupyter Notebook 中,选择菜单?#8220;代码执行E序QRuntimeQ?/strong>”Q?#8220;更改q行cdQChange runtime typeQ?/strong>”Q这时将看到以下弹出H口Q?/span>

保“g加速器QHardware acceleratorQ?#8221;讄?GPUQ默认ؓ(f) CPUQ?span style="color: #444444; font-family: "Microsoft Yahei", "Helvetica Neue", Helvetica, Arial, sans-serif; background-color: #ffffff;">讄完毕后点M存?/span>


值得注意的是认W记本处?strong>已连?/strong>的状态:(x)



(g)查是否真的开启了 GPUQ即当前q接CGPU实例Q,可以直接?Jupyter Notebook 中运行以下命?/span>Q?/span>


import tensorflow as tf
device_name = tf.test.gpu_device_name()
if device_name != '/device:GPU:0':
 raise SystemError('GPU device not found')
print('Found GPU at: {}'.format(device_name))

 

若输Z下语句,则表明已l用了 GPU 实例?/span>


Found GPU at: /device:GPU:0


但是Q由于在U?GPU 资源有限Q有时候可能会(x)出现下面的问题提C:(x)



 

pPh允许你一ơ最多持l?12 时的免?GPU?/span>


2. 安装?/span>


目前Q在 Google Colaboratory 中安装的软gq不是持久的Q意味着每次重新q接实例旉需要重新安装。但是,Colab 已经默认安装了需要有用的库,安装新的库也q难事Q方法也有好几种?/span>


但需要注意的是,安装M需要从源代码构建的软g可能需要很长的旉?/span>


Colab 同时支持 pip ?apt 包管理器。无论?zhn)使用的是哪一个,C要在命o(h)前面加上W号 “!”?/span>


# Install Keras with pip
!pip install -q keras
import keras

>
>> Using TensorFlow backend.

#
Install GraphViz with apt
!apt-get install graphviz -y



3. 上传q用数据文?/span>


我们一般都需要在 Colab W记本中使用数据Q对吧?你可以?wget 之类的工具从|络上获取数据,但是如果你有一些本地文Ӟ想上传到你的h盘中的 Colab 环境里ƈ使用它们Q该怎么做呢Q?/span>


很简单,只需 3 步即可实玎ͼ


首先使用以下命o(h)调用W记本中的文仉择器:(x)


from google.colab import files
uploaded = files.upload()


q行之后Q我们就?x)发现单?cell 下出C“选择文g”按钮Q?/span>



q样可以直接选择你想上传的文件啦Q?/span>


选择文g后,使用以下q代Ҏ(gu)上传文g以查扑օ键名Q命令如下:(x)


for fn in uploaded.keys():
 print('User uploaded file "{name}" with length {length} bytes'.format(name=fn, length=len(uploaded[fn])))


例如待上传的?iris.csv 文gQ若q行没有问题的话Q应该出现类g面的提示语句Q?/span>


User uploaded file "iris.csv" with length 3716 bytes


最后,׃用以下命令将文g的内容加载到 Pandas ?DataFrame 中了Q?/span>


import pandas as pd
import io
df = pd.read_csv(io.StringIO(uploaded['iris.csv'].decode('utf-8')))
print(df)


q种上传文g的方法是不是很简单呢Q当?dng)上传和用数据文件还有其它的?gu)Q但是我发现q一Ҏ(gu)最单明了?/span>


以上是关于 Google Calaboratory ?3 个非常实用的技巧,赶紧试一下吧Q?/span>


最后,可能有的读者朋友对 Google Calaboratory 不太了解的,可以查看我之前写的一文章:(x)如何在免费云端运?Python 深度学习(fn)框架Q?/strong>链接如下Q?/span>


https://redstonewill.com/1493/


也可以点?strong>阅读原文查看Q?/span>


Reference:
https://mp.weixin.qq.com/s/vLnBFPZNvIjs4R7d4_6M_g


杰哥 2019-02-13 23:56 发表评论
]]>
[zz]Python中下划线?U含?/title><link>http://www.shnenglu.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.shnenglu.com/guijie/archive/2019/02/02/216230.html</guid><wfw:comment>http://www.shnenglu.com/guijie/comments/216230.html</wfw:comment><comments>http://www.shnenglu.com/guijie/archive/2019/02/02/216230.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/guijie/comments/commentRss/216230.html</wfw:commentRss><trackback:ping>http://www.shnenglu.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, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", "Source Han Sans SC", "Noto Sans CJK SC", "WenQuanYi Micro Hei", 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;">分n一文章:(x)<a 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中单下划U和双下划线Q?dunder"Q的各种含义和命名约定,名称修饰Qname manglingQ的工作原理Q以?qing)它如何影响你自qPythoncR?/p><p style="margin: 1.4em 0px;">单下划线和双下划U在Python变量和方法名UC都各有其含义。有一些含义仅仅是依照U定Q被视作是对E序员的提示 - 而有一些含义是由Python解释器严格执行的?/p><p style="margin: 1.4em 0px;">如果你想知道“Python变量和方法名UC单下划线和双下划U的含义是什么?”Q我?x)尽我所能在q里Z解答?/p><p style="margin: 1.4em 0px;">在本文中Q我讨Z下五U下划线模式和命名约定,以及(qing)它们如何影响PythonE序的行为:(x)</p><ul style="padding: 0px; margin: 1.4em 0px; display: table;"><li style="list-style: none; display: table-row;">单前g划线Q_var</li><li style="list-style: none; display: table-row;">单末下划线Qvar_</li><li style="list-style: none; display: table-row;">双前g划线Q__var</li><li style="list-style: none; display: table-row;">双前导和末尾下划U:(x)__var__</li><li style="list-style: none; display: table-row;">单下划线Q_</li></ul><p style="margin: 1.4em 0px;">在文章结֤Q你可以扑ֈ一个简短的“速查?#8221;Qȝ了五U不同的下划U命名约定及(qing)其含义,以及(qing)一个简短的视频教程Q可让你亲n体验它们的行为?/p><p style="margin: 1.4em 0px;">让我们马上开始!</p><h2>1. 单前g划线 _var</h2><p style="margin: 1.4em 0px;">当涉?qing)到变量和方法名U时Q单个下划线前缀有一个约定俗成的含义?它是对程序员的一个提C?- 意味着PythonC֌一致认为它应该是什么意思,但程序的行ؓ(f)不受影响?/p><p style="margin: 1.4em 0px;">下划U前~的含义是告知其他E序员:(x)以单个下划线开头的变量或方法仅供内部用?该约定在PEP 8中有定义?/p><p style="margin: 1.4em 0px;">q不是Python强制规定的?Python不像Java那样?#8220;U有”?#8220;公共”变量之间有很强的区别?q就像有人提Z一个小的下划U警告标志,_(d)(x)</p><blockquote style="margin: 1.4em 0px; padding-left: 1em; color: #646464; border-left-width: 3px; border-left-color: #d3d3d3;">“嘿,q不是真的要成ؓ(f)cȝ公共接口的一部分。不ȝ它就好?#8220;</blockquote><p style="margin: 1.4em 0px;">看看下面的例子:(x)</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, "Andale Mono", "lucida console", "Courier New", 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;">如果你实例化此类Qƈ试讉K在__init__构造函C定义的foo和_bar属性,?x)发生什么情况? 让我们来看看Q?/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, "Andale Mono", "lucida console", "Courier New", monospace; font-size: inherit; background-color: inherit;">>>> t = Test() >>> t.foo 11 >>> t._bar 23 </code></pre></div><p style="margin: 1.4em 0px;">你会(x)看到_bar中的单个下划Uƈ没有L我们“q入”cdƈ讉K该变量的倹{?/p><p style="margin: 1.4em 0px;">q是因ؓ(f)Python中的单个下划U前~仅仅是一个约?- 臛_相对于变量和Ҏ(gu)名而言?/p><p style="margin: 1.4em 0px;">但是Q前g划线的确?x)?jing)响从模块中导入名U的方式?/p><p style="margin: 1.4em 0px;">假设你在一个名为my_module的模块中有以下代码:(x)</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, "Andale Mono", "lucida console", "Courier New", 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;">现在Q如果用通配W从模块中导入所有名Uͼ则Python不会(x)导入带有前导下划U的名称Q除非模块定义了覆盖此行为的__all__列表Q:(x)</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, "Andale Mono", "lucida console", "Courier New", monospace; font-size: inherit; background-color: inherit;">>>> from my_module import * >>> external_func() 23 >>> _internal_func() NameError: "name '_internal_func' is not defined" </code></pre></div><p style="margin: 1.4em 0px;">Z说一下,应该避免通配W导入,因ؓ(f)它们使名U空间中存在哪些名称不清楚?Z清楚赯Q坚持常规导入更好?br /></p><p style="margin: 1.4em 0px;">与通配W导入不同,常规导入不受前导单个下划U命名约定的影响Q?/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, "Andale Mono", "lucida console", "Courier New", monospace; font-size: inherit; background-color: inherit;">>>> import my_module >>> my_module.external_func() 23 >>> my_module._internal_func() 42 </code></pre></div><p style="margin: 1.4em 0px;">我知道这一点可能有点o(h)人困惑?如果你遵循PEP 8推荐Q避免通配W导入,那么你真正需要记住的只有q个Q?/p><blockquote style="margin: 1.4em 0px; padding-left: 1em; color: #646464; border-left-width: 3px; border-left-color: #d3d3d3;">单个下划U是一个Python命名U定Q表C个名U是供内部用的?它通常不由Python解释器强制执行,仅仅作ؓ(f)一U对E序员的提示?/blockquote><h2>2. 单末下划线 var_</h2><p style="margin: 1.4em 0px;">有时候,一个变量的最合适的名称已经被一个关键字所占用?因此Q像class或defq样的名UC能用作Python中的变量名称?在这U情况下Q你可以附加一个下划线来解军_名冲H:(x)</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, "Andale Mono", "lucida console", "Courier New", monospace; font-size: inherit; background-color: inherit;">>>> def make_object(name, class): SyntaxError: "invalid syntax" >>> def make_object(name, class_): ... pass </code></pre></div><p style="margin: 1.4em 0px;">MQ单个末下划线Q后~Q是一个约定,用来避免与Python关键字生命名冲H?PEP 8解释了这个约定?/p><h2>3. 双前g划线 __var</h2><p style="margin: 1.4em 0px;">到目前ؓ(f)止,我们所涉及(qing)的所有命名模式的含义Q来自于已达成共识的U定?而对于以双下划线开头的Pythoncȝ属性(包括变量和方法)Q情况就有点不同了?/p><p style="margin: 1.4em 0px;">双下划线前缀?x)导致Python解释器重写属性名Uͼ以避免子cM的命名冲H?/p><p style="margin: 1.4em 0px;">q也叫做名称修饰Qname manglingQ?- 解释器更改变量的名称Q以便在c被扩展的时候不Ҏ(gu)产生冲突?/p><p style="margin: 1.4em 0px;">我知道这听v来很抽象?因此Q我l合了一个小的代码CZ来予以说明:(x)</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, "Andale Mono", "lucida console", "Courier New", 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()函数来看看这个对象的属性:(x)</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, "Andale Mono", "lucida console", "Courier New", monospace; font-size: inherit; background-color: inherit;">>>> t = Test() >>> 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;">以上是这个对象属性的列表?让我们来看看q个列表QƈL我们的原始变量名UfooQ_bar和__baz - 我保证你?x)注意到一些有的变化?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的Ş式显C在cM?像我之前说q的Q在q种情况下,前导下划U仅仅是一个约定?l程序员一个提C已?/li><li style="list-style: none; display: table-row;">然而,对于self.__baz而言Q情늜h有点不同?当你在该列表中搜索__bazӞ你会(x)看不到有q个名字的变量?/li></ul><p style="margin: 1.4em 0px;">__bazZ么情况了Q?/p><p style="margin: 1.4em 0px;">如果你仔l观察,你会(x)看到此对象上有一个名为_Test__baz的属性?q就是Python解释器所做的名称修饰?它这样做是ؓ(f)了防止变量在子类中被重写?/p><p style="margin: 1.4em 0px;">让我们创建另一个扩展Testcȝc,q尝试重写构造函Cd的现有属性:(x)</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, "Andale Mono", "lucida console", "Courier New", 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;">现在Q你认ؓ(f)fooQ_bar和__baz的g(x)出现在这个ExtendedTestcȝ实例上吗Q?我们来看一看:(x)</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, "Andale Mono", "lucida console", "Courier New", monospace; font-size: inherit; background-color: inherit;">>>> t2 = ExtendedTest() >>> t2.foo 'overridden' >>> t2._bar 'overridden' >>> t2.__baz AttributeError: "'ExtendedTest' object has no attribute '__baz'" </code></pre></div><p style="margin: 1.4em 0px;">{一下,当我们尝试查看t2 .__ baz的值时Qؓ(f)什么我们会(x)得到AttributeErrorQ?名称修饰被再ơ触发了Q?事实证明Q这个对象甚x有__baz属性:(x)</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, "Andale Mono", "lucida console", "Courier New", monospace; font-size: inherit; background-color: inherit;">>>> 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以防止意外修改:(x)</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, "Andale Mono", "lucida console", "Courier New", monospace; font-size: inherit; background-color: inherit;">>>> t2._ExtendedTest__baz 'overridden' </code></pre></div><p style="margin: 1.4em 0px;">但原来的_Test__bazq在Q?/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, "Andale Mono", "lucida console", "Courier New", monospace; font-size: inherit; background-color: inherit;">>>> t2._Test__baz 42 </code></pre></div><p style="margin: 1.4em 0px;">双下划线名称修饰对程序员是完全透明的?下面的例子证实了q一点:(x)</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, "Andale Mono", "lucida console", "Courier New", monospace; font-size: inherit; background-color: inherit;">class ManglingTest: def __init__(self): self.__mangled = 'hello' def get_mangled(self): return self.__mangled >>> ManglingTest().get_mangled() 'hello' >>> ManglingTest().__mangled AttributeError: "'ManglingTest' object has no attribute '__mangled'" </code></pre></div><p style="margin: 1.4em 0px;">名称修饰是否也适用于方法名Uͼ 是的Q也适用。名UCC(x)影响在一个类的上下文中,以两个下划线字符Q?dunders"Q开头的<span style="font-weight: 600;">所?/span>名称Q?/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, "Andale Mono", "lucida console", "Courier New", monospace; font-size: inherit; background-color: inherit;">class MangledMethod: def __method(self): return 42 def call_it(self): return self.__method() >>> MangledMethod().__method() AttributeError: "'MangledMethod' object has no attribute '__method'" >>> MangledMethod().call_it() 42 </code></pre></div><p style="margin: 1.4em 0px;">q是另一个也o(h)人惊讶的q用名称修饰的例子:(x)</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, "Andale Mono", "lucida console", "Courier New", monospace; font-size: inherit; background-color: inherit;">_MangledGlobal__mangled = 23 class MangledGlobal: def test(self): return __mangled >>> MangledGlobal().test() 23 </code></pre></div><p style="margin: 1.4em 0px;">在这个例子中Q我声明了一个名为_MangledGlobal__mangled的全局变量。然后我在名为MangledGlobal的类的上下文中访问变量。由于名UC饎ͼ我能够在cȝtest()Ҏ(gu)内,以__mangled来引用_MangledGlobal__mangled全局变量?br /><br />Python解释器自动将名称__mangled扩展为_MangledGlobal__mangledQ因为它以两个下划线字符开头。这表明名称修饰不是专门与类属性关联的。它适用于在cM下文中用的两个下划U字W开头的M名称?br /><br />有很多要吸收的内容吧?br /><br />老实_(d)q些例子和解释不是从我脑子里y出来的。我作了一些研I和加工才弄出来。我一直用PythonQ有很多q了Q但是像q样的规则和Ҏ(gu)情况q不L现在脑里?br /><br />有时候程序员最重要的技能是“模式识别”Q而且知道在哪里查阅信息。如果?zhn)在这一点上感到有点不知所措,请不要担心。慢慢来Q试试这文章中的一些例子?br /><br />让这些概念完全沉怸来,以便你能够理解名UC饰的M思\Q以?qing)我向(zhn)展示的一些其他的行ؓ(f)。如果有一天你和它们不期而遇Q你?x)知道在文档中按什么来查?/p><h2>4. 双前导和双末下划线 _var_</h2><p style="margin: 1.4em 0px;">也许令h惊讶的是Q如果一个名字同时以双下划线开始和l束Q则不会(x)应用名称修饰?由双下划U前~和后~包围的变量不?x)被Python解释器修改:(x)</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, "Andale Mono", "lucida console", "Courier New", monospace; font-size: inherit; background-color: inherit;">class PrefixPostfixTest: def __init__(self): self.__bam__ = 42 >>> PrefixPostfixTest().__bam__ 42 </code></pre></div><p style="margin: 1.4em 0px;">但是QPython保留了有双前导和双末下划线的名Uͼ用于Ҏ(gu)用途?q样的例子有Q__init__对象构造函敎ͼ或__call__ --- 它得一个对象可以被调用?/p><p style="margin: 1.4em 0px;">q些dunderҎ(gu)通常被称为神奇方?- 但PythonC֌中的许多人(包括我自己)都不喜欢q种Ҏ(gu)?/p><p style="margin: 1.4em 0px;">最好避免在自己的程序中使用以双下划U(“dunders”Q开头和l尾的名Uͼ以避免与来Python语言的变化生冲H?/p><h2>5.单下划线 _</h2><p style="margin: 1.4em 0px;">按照?fn)惯Q有时候单个独立下划线是用作一个名字,来表C某个变量是临时的或无关紧要的?br /></p><p style="margin: 1.4em 0px;">例如Q在下面的@环中Q我们不需要访问正在运行的索引Q我们可以?#8220;_”来表C它只是一个(f)时|(x)</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, "Andale Mono", "lucida console", "Courier New", monospace; font-size: inherit; background-color: inherit;">>>> for _ in range(32): ... print('Hello, World.') </code></pre></div><p style="margin: 1.4em 0px;">你也可以在拆?unpacking)表达式中单个下划线用作“不关心的”变量Q以忽略特定的倹{?同样Q这个含义只?#8220;依照U定”Qƈ不会(x)在Python解释器中触发Ҏ(gu)的行为?单个下划U仅仅是一个有效的变量名称Q会(x)有这个用途而已?/p><p style="margin: 1.4em 0px;">在下面的代码CZ中,我将汽R元组拆分为单独的变量Q但我只寚w色和里程值感兴趣?但是Qؓ(f)了拆分表达式成功运行,我需要将包含在元l中的所有值分配给变量?在这U情况下Q?#8220;_”作ؓ(f)占位W变量可以派上用场:(x)</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, "Andale Mono", "lucida console", "Courier New", monospace; font-size: inherit; background-color: inherit;">>>> car = ('red', 'auto', 12, 3812.4) >>> color, _, _, mileage = car >>> color 'red' >>> mileage 3812.4 >>> _ 12 </code></pre></div><p style="margin: 1.4em 0px;">除了用作临时变量之外Q?#8220;_”是大多数Python REPL中的一个特D变量,它表C由解释器评估的最q一个表辑ּ的结果?/p><p style="margin: 1.4em 0px;">q样很方便了,比如你可以在一个解释器?x)话中访问先前计的l果Q或者,你是在动态构建多个对象ƈ与它们交互,无需事先l这些对象分配名字:(x)</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, "Andale Mono", "lucida console", "Courier New", monospace; font-size: inherit; background-color: inherit;">>>> 20 + 3 23 >>> _ 23 >>> print(_) 23 >>> list() [] >>> _.append(1) >>> _.append(2) >>> _.append(3) >>> _ [1, 2, 3] </code></pre></div><h2>Python下划U命名模?- 结</h2><p style="margin: 1.4em 0px;">以下是一个简短的结Q即“速查?#8221;Q罗列了我在本文中谈到的五种Python下划U模式的含义Q?/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;">你想更深入了解学?fn)Python知识体系Q你可以看一下我们花费了一个多月整理了上百时的几百个知识点体pd容:(x)</p><p style="margin: 1.4em 0px 0px;"><a 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基础教程W记</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, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", "Source Han Sans SC", "Noto Sans CJK SC", "WenQuanYi Micro Hei", 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, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", "Source Han Sans SC", "Noto Sans CJK SC", "WenQuanYi Micro Hei", 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="{"card":{"content":{"type":"Topic","token":"19552832"}}}" 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 target="_blank" style="text-decoration-line: none;"><div style="position: relative; display: inline-block;"><div class="gghpwax" 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.shnenglu.com/guijie/aggbug/216230.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/guijie/" target="_blank">杰哥</a> 2019-02-02 01:51 <a href="http://www.shnenglu.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.shnenglu.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.shnenglu.com/guijie/archive/2019/01/03/216164.html</guid><wfw:comment>http://www.shnenglu.com/guijie/comments/216164.html</wfw:comment><comments>http://www.shnenglu.com/guijie/archive/2019/01/03/216164.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/guijie/comments/commentRss/216164.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/guijie/services/trackbacks/216164.html</trackback:ping><description><![CDATA[<div>Python3中map函数</div><div>在Python2中map函数?x)返回一个list列表Q如代码Q?/div><div>>>> def f(x, y): return (x, y)</div><div>>>> l1 = [ 0, 1, 2, 3, 4, 5, 6 ]</div><div>>>> l2 = [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ]</div><div></div><div>q回l果如下Q?/div><div>>>> map(f, l1, l2)</div><div>[(0, 'Sun'), (1, 'Mon'), (2, 'Tue'), (3, 'Wed'), (4, 'Thu'), (5, 'Fri'), (6, 'Sat')]</div><div></div><div>但是Q在Python3中返回结果如下:(x)</div><div>>>> map(f1, l1, l2)</div><div><map object at 0x00000000021DA860></div><div></div><div>如果惌得到Python2的那U结果,卌回list列表Q那么必ȝlist作用于mapQ如下:(x)</div><div>>>> 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.shnenglu.com/guijie/aggbug/216164.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/guijie/" target="_blank">杰哥</a> 2019-01-03 12:01 <a href="http://www.shnenglu.com/guijie/archive/2019/01/03/216164.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[zz]python求数字位数的Ҏ(gu)http://www.shnenglu.com/guijie/archive/2018/12/29/216152.html杰哥杰哥Sat, 29 Dec 2018 06:00:00 GMThttp://www.shnenglu.com/guijie/archive/2018/12/29/216152.htmlhttp://www.shnenglu.com/guijie/comments/216152.htmlhttp://www.shnenglu.com/guijie/archive/2018/12/29/216152.html#Feedback0http://www.shnenglu.com/guijie/comments/commentRss/216152.htmlhttp://www.shnenglu.com/guijie/services/trackbacks/216152.htmlW一U:(x)
利用str()函数数字{化成字符Ԍ再利用len()函数判断位长?/p>
 1 a=Int(raw_input("the number you want type in:")   
2
b=len(str(a))
3
print b

W二U:(x)
利用?0取商Q通过循环ơ数判断位数?/p>

c=0
a=int(raw_input("the number you want type in:"))
while a!=0:
      a=a/10
      c +=1
print c


Reference:

https://www.cnblogs.com/54Leo/p/6133270.html


杰哥 2018-12-29 14:00 发表评论
]]>
colabhttp://www.shnenglu.com/guijie/archive/2018/12/21/216130.html杰哥杰哥Fri, 21 Dec 2018 01:07:00 GMThttp://www.shnenglu.com/guijie/archive/2018/12/21/216130.htmlhttp://www.shnenglu.com/guijie/comments/216130.htmlhttp://www.shnenglu.com/guijie/archive/2018/12/21/216130.html#Feedback0http://www.shnenglu.com/guijie/comments/commentRss/216130.htmlhttp://www.shnenglu.com/guijie/services/trackbacks/216130.html
How to create a folder in colab? h搜烦(ch): colab new folder扑ֈq个链接: https://medium.com/lean-in-women-in-tech-india/google-colab-the-beginners-guide-5ad3b417dfa
Create a Colab Notebook
Open Google Colab.
Click on ‘New Notebook’ and select Python 2 notebook or Python 3 notebook.
OR
Open Google Drive.
Create a new folder for the project.
Click on ‘New’ > ‘More’ > ‘Colaboratory’.
Google Drive -> 我的云端盘 -> 新徏文g? Click on ‘New’ > ‘More’ > ‘Colaboratory’,q个怎么操作? 例如选中"02_backprop.ipynb", 打开方式, 兌更多应用, 选择colab. q样在google drive里就可以选中"02_backprop.ipynb", 打开方式, ‘Colaboratory’卛_.但直接打开Colab, Google drive里面是没?02_backprop.ipynb", Recent有。暂不折腾这个问? Zhengxia说colab应该?x)?否则大家都把它当|盘使用

02_backprop.ipynb, 最开始Forward propagation上面, device改ؓ(f)GPU (device = torch.device('cuda') # Uncomment this to run on GPU),没法q行原因? zhengxia says: Edit -> Notepad settings -> select GPU.如果一个新?sh)脑Q你肯定要自己配|下cuda和cudnnQ谷歌胦(ch)大气_,相当q些都帮你做好了?/div>


杰哥 2018-12-21 09:07 发表评论
]]>[zz] matplotlib.pyplot 中显C图像的两种模式Q交互和dQ及(qing)其在Pythond中的应用http://www.shnenglu.com/guijie/archive/2018/12/17/216124.html杰哥杰哥Sun, 16 Dec 2018 22:10:00 GMThttp://www.shnenglu.com/guijie/archive/2018/12/17/216124.htmlhttp://www.shnenglu.com/guijie/comments/216124.htmlhttp://www.shnenglu.com/guijie/archive/2018/12/17/216124.html#Feedback0http://www.shnenglu.com/guijie/comments/commentRss/216124.htmlhttp://www.shnenglu.com/guijie/services/trackbacks/216124.html介绍

在用matplotlib的过E中Q发C能像matlab一样同时开几个H口q行比较Q于是查询得知了交互模式Q但是放在脚本里q行的适合却L一闪而过Q图像ƈ不停留,遂仔l阅d理解了一下文档,C解决办法Q问题比较简单,仅供菜鸟参考?/p>

python可视化库matplotlib有两U显C模式:(x)

  1. dQblockQ模?/li>
  2. 交互QinteractiveQ模?/li>

在Python Consol命o(h)行中q行脚本Q默认是d模式。而在python IDE中运行脚本,matplotlib默认是交互模式。(使用python命o(h)行运行脚本不能同时显CZ同图像)

其中的区别是:

在交互模式下Q?/p>

  • plt.plot(x)或plt.imshow(x)是直接出囑փQ不需要plt.show()
  • 如果在脚本中使用ion()命o(h)开启了交互模式Q没有用ioff()关闭的话Q则囑փ?x)一闪而过Qƈ不会(x)常留。要想防止这U情况,需要在plt.show()之前加上ioff()命o(h)或者?span style="box-sizing: border-box; outline: 0px; font-weight: 700; overflow-wrap: break-word;">plt.pause(seconds)廉昄?/li>

在阻塞模式下Q?/p>

  • 打开一个窗口以后必d掉才能打开下一个新的窗口。这U情况下Q默认是不能像Matlab一样同时开很多H口q行Ҏ(gu)的?/li>
  • plt.plot(x)或plt.imshow(x)是直接出囑փQ需要plt.show()后才能显C图?/li>

CZ

下面q个例子讲的是如何像matlab一样同时打开多个H口昄囄或线条进行比较,同时也是在脚本中开启交互模式后囑փ一闪而过的解军_法:(x)

  1. import matplotlib.pyplot as plt
  2. plt.ion() # 打开交互模式
  3. # 同时打开两个H口昄囄
  4. plt.figure()
  5. plt.imshow(i1)
  6. plt.figure()
  7. plt.imshow(i2)
  8. # 昄前关掉交互模?/span>
  9. plt.ioff()
  10. plt.show()

 Reference:
https://blog.csdn.net/wonengguwozai/article/details/79686062



杰哥 2018-12-17 06:10 发表评论
]]>
Error:Cannot start process, the path specified for working directory is not a directoryhttp://www.shnenglu.com/guijie/archive/2018/11/05/216033.html杰哥杰哥Mon, 05 Nov 2018 01:59:00 GMThttp://www.shnenglu.com/guijie/archive/2018/11/05/216033.htmlhttp://www.shnenglu.com/guijie/comments/216033.htmlhttp://www.shnenglu.com/guijie/archive/2018/11/05/216033.html#Feedback0http://www.shnenglu.com/guijie/comments/commentRss/216033.htmlhttp://www.shnenglu.com/guijie/services/trackbacks/216033.htmlIf 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.
PyCharm change working directory of console
Settings -> Build Execution Deployment -> Console -> Python Console

However, if I change the working directory every time, this gives me much trouble. Zhengxia is inspired by
"
I finally solved the problem.

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.

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 https://stackoverflow.com/questions/28202273/working-directory-error/28975990.

He gave me the suggestion: File -> open, open the directory rather than open the file. For example, "
GAN\code\generative-models-master", he said that it is better to make the environment of the pycharm projects consistent (pycharm工程默认加蝲一个环境变?最好同一个工E下环境一?. Then a file ".idea" will be created. In this way, all files of this folder will be seen as a part of this project. In the file ".idea", there will be the historical record, the path setting such as the interpreter. Generally, we do not use this file.

Reference:
https://stackoverflow.com/questions/37818938/pycharm-change-working-directory-of-console


杰哥 2018-11-05 09:59 发表评论
]]>
PyCharm skills: indentionhttp://www.shnenglu.com/guijie/archive/2018/10/14/216008.html杰哥杰哥Sat, 13 Oct 2018 21:08:00 GMThttp://www.shnenglu.com/guijie/archive/2018/10/14/216008.htmlhttp://www.shnenglu.com/guijie/comments/216008.htmlhttp://www.shnenglu.com/guijie/archive/2018/10/14/216008.html#Feedback0http://www.shnenglu.com/guijie/comments/commentRss/216008.htmlhttp://www.shnenglu.com/guijie/services/trackbacks/216008.htmlShift + Tab: Left indention
Sui Li says that word, powerpoint and group wiki (foreseer) also use this.

杰哥 2018-10-14 05:08 发表评论
]]>
How to read *.mat file in python?http://www.shnenglu.com/guijie/archive/2018/10/14/216007.html杰哥杰哥Sat, 13 Oct 2018 20:47:00 GMThttp://www.shnenglu.com/guijie/archive/2018/10/14/216007.htmlhttp://www.shnenglu.com/guijie/comments/216007.htmlhttp://www.shnenglu.com/guijie/archive/2018/10/14/216007.html#Feedback0http://www.shnenglu.com/guijie/comments/commentRss/216007.htmlhttp://www.shnenglu.com/guijie/services/trackbacks/216007.htmlimport scipy.io as sio
mnist_49_3000 = sio.loadmat('mnist_49_3000.mat')


杰哥 2018-10-14 04:47 发表评论
]]>
How to read *.data in Matlab and Pythonhttp://www.shnenglu.com/guijie/archive/2018/10/13/216005.html杰哥杰哥Fri, 12 Oct 2018 20:33:00 GMThttp://www.shnenglu.com/guijie/archive/2018/10/13/216005.htmlhttp://www.shnenglu.com/guijie/comments/216005.htmlhttp://www.shnenglu.com/guijie/archive/2018/10/13/216005.html#Feedback0http://www.shnenglu.com/guijie/comments/commentRss/216005.htmlhttp://www.shnenglu.com/guijie/services/trackbacks/216005.htmlSee P2 of "HW2_545_2018_"

In Matlab:
z = dlmread('spambase.data',',');
In Python:
import numpy as np
z = np.genfromtxt('spambase.data', dtype=float, delimiter=',')


杰哥 2018-10-13 04:33 发表评论
]]>
product in python: np.dot, np.multiply, *http://www.shnenglu.com/guijie/archive/2018/10/06/215992.html杰哥杰哥Sat, 06 Oct 2018 00:33:00 GMThttp://www.shnenglu.com/guijie/archive/2018/10/06/215992.htmlhttp://www.shnenglu.com/guijie/comments/215992.htmlhttp://www.shnenglu.com/guijie/archive/2018/10/06/215992.html#Feedback0http://www.shnenglu.com/guijie/comments/commentRss/215992.htmlhttp://www.shnenglu.com/guijie/services/trackbacks/215992.htmlhttps://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.dot.html

Dot product of two arrays. Specifically,

  • If both a and b are 1-D arrays, it is inner product of vectors (without complex conjugation).

  • If both a and b are 2-D arrays, it is matrix multiplication, but using matmul or a @ b is preferred.

  • If either a or b is 0-D (scalar), it is equivalent to multiply and using numpy.multiply(a, b) or a * b is preferred.

  • If a is an N-D array and b is a 1-D array, it is a sum product over the last axis of a and b.

  • If a is an N-D array and b is an M-D array (where M>=2), it is a sum product over the last axis of a and the second-to-last axis of b:

    dot(a, b)[i,j,k,m] = sum(a[i,j,:] * b[k,:,m])
What does the last two points mean?
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.

杰哥 2018-10-06 08:33 发表评论
]]>
Interpreter of Pycharmhttp://www.shnenglu.com/guijie/archive/2018/10/05/215990.html杰哥杰哥Fri, 05 Oct 2018 00:59:00 GMThttp://www.shnenglu.com/guijie/archive/2018/10/05/215990.htmlhttp://www.shnenglu.com/guijie/comments/215990.htmlhttp://www.shnenglu.com/guijie/archive/2018/10/05/215990.html#Feedback0http://www.shnenglu.com/guijie/comments/commentRss/215990.htmlhttp://www.shnenglu.com/guijie/services/trackbacks/215990.htmlYang Zhou says that there can be infinity python.exe in your computer. Maybe some install numpy while some not.
Some other interpreters on my computer: 
C:\Users\think\PycharmProjects\Test\venv\Scripts\python.exe       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.
E:\OneDrive - ustc.edu\PycharmProjects\Test\venv\Scripts
I have set C:\Users\think\Anaconda3\python.exe as the default interpreter. This interpreter has installed numpy. How can we set this? pycharm -> File -> Default settings
pycharm -> File -> settings -> show all -> existing environment
One interesting fact is that if I name a directory as _numpy and "import numpy as np" will have error. This error can be solved by changing the name of the directory from _numpy to _numpy1.

Reference:
https://blog.csdn.net/chengzihe_lu/article/details/79639804




杰哥 2018-10-05 08:59 发表评论
]]>
pycharm 默认布局׃http://www.shnenglu.com/guijie/archive/2018/08/28/215883.html杰哥杰哥Mon, 27 Aug 2018 21:26:00 GMThttp://www.shnenglu.com/guijie/archive/2018/08/28/215883.htmlhttp://www.shnenglu.com/guijie/comments/215883.htmlhttp://www.shnenglu.com/guijie/archive/2018/08/28/215883.html#Feedback0http://www.shnenglu.com/guijie/comments/commentRss/215883.htmlhttp://www.shnenglu.com/guijie/services/trackbacks/215883.html菜单  Window>restore default layout。但是我的菜单栏没有window。ؕ点,菜单栏下面一行右键,有Customize Menus and ToolbarsQ?Restore All Defaults。菜单栏有了Window

杰哥 2018-08-28 05:26 发表评论
]]>
matlab errorbarhttp://www.shnenglu.com/guijie/archive/2012/09/06/189645.html杰哥杰哥Thu, 06 Sep 2012 01:28:00 GMThttp://www.shnenglu.com/guijie/archive/2012/09/06/189645.htmlhttp://www.shnenglu.com/guijie/comments/189645.htmlhttp://www.shnenglu.com/guijie/archive/2012/09/06/189645.html#Feedback0http://www.shnenglu.com/guijie/comments/commentRss/189645.htmlhttp://www.shnenglu.com/guijie/services/trackbacks/189645.html

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 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:
(1) D(ax+b) = a*a*D(x),
(2) the second line of "中心极限定理". x bar is seen as a random variable,
we have std(x bar) = std(x)/sqrt(n).
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 standard error should be computed first and then be used as the input of xerr and yerr. 
I check my TNNLS 2017 paper and I find that I show the std. Maybe next time I can show the standard error.


q个函数的意思是Q?br />ERRORBAR(X,Y,L,U)QX是自变量QY是因变量QL是Y的变动下限,U是Y的变动上?/p>

errorbar(X,Y,E)  X是自变量QY是因变量QE是Y的变动绝对差倹{?/p>我自己写的例子:(x)

 X=[1 2 3];
Y= [ 0.2 0.4 0.2];
L=[0.1 0.03 0.03];U=[0.1 0.3 0.2];
E= [0.1 0.3 0.2];
figure;
hold on;%一定要有这一句,否则有问?/div>
bar(X,Y);
errorbar(X,Y,E,'Marker','none','LineStyle','none');
figure;
hold on;%一定要有这一句,否则有问?/div>
errorbar(X,Y,E);%以下注释的两句用q一句就可以?br />%plot(X,Y);
%errorbar(X,Y,E,'Marker','none','LineStyle','none');
figure;
hold on;%一定要有这一句,否则有问?/div>
bar(X,Y);
errorbar(X,Y,L,U);%,'Marker','none','LineStyle','none'不能?/div>
说明Q必M用hold onQbar是画q图, errorbar是花竖线
--------------------------------------------------------------------以下可不?---------------------------------------------------------------------------
example1Q?/span>

 

       x = 1:10;
       y = sin(x);
       e = std(y)*ones(size(x));
       errorbar(x,y,e)

 

matlab的errorbar函数

example2Q?/span> 
% 生成CZ数据
x=1:10;
y=cumsum(randn(1,10));
lower = y - (rand(1,10));
upper = y + (rand(1,10));

% ׃errorbar函数使用相对差值在囑Ş上绘图,所?/span>
% 需要将l对差D{变ؓ(f)相对差倹{?/span>
L = y - lower;
U = upper -y;

% l图旉要设?hold on
% q?/span>
clf;
figure(1);
hold on;
bar(x,y);
% 此处需要隐藏折U?/span>
errorbar(x,y,L,U,'Marker','none','LineStyle','none');

% 折线?/span>
figure(2);
hold('on');
plot( x, y);
errorbar( x, y, L, U); 

Reference:
http://blog.sina.com.cn/s/blog_61010ebe0100l9c9.html 
http://bio-spring.info/wp/?p=85 

杰哥 2012-09-06 09:28 发表评论
]]>Python path; matlab function load, savehttp://www.shnenglu.com/guijie/archive/2012/06/20/179529.html杰哥杰哥Wed, 20 Jun 2012 13:07:00 GMThttp://www.shnenglu.com/guijie/archive/2012/06/20/179529.htmlhttp://www.shnenglu.com/guijie/comments/179529.htmlhttp://www.shnenglu.com/guijie/archive/2012/06/20/179529.html#Feedback0http://www.shnenglu.com/guijie/comments/commentRss/179529.htmlhttp://www.shnenglu.com/guijie/services/trackbacks/179529.htmlmatlab函数l(f)oad 目录Qsave
目录都用反斜杠,q样windows和Linux目录都认QLinux只认反斜?nbsp;
当前目录Q?/span>
for s=1:20
    filename = num2str(s);
    load (filename);
end
当前目录的下一层目?/span>Q?/span>
for s=1:20
    %filename = ['./50Train/',num2str(s),'.mat'];  %q种方式应该更快Q省得字W串操作
    %filename = ['50Train/',num2str(s)];    %最前面?/不加也可?/span>
    %filename = ['./50Train/',num2str(s)];
    filename = strcat('./50Train/',num2str(s));
    load (filename);
end
当前目录的上一层目录:(x)
for s=1:20
    %filename = ['../50Train/',num2str(s),'.mat']; 
    %filename = ['../50Train/',num2str(s)];
    filename = strcat('../50Train/',num2str(s));
    load (filename);
end

dataName = '../Parmprint.mat';%'../Parmprint/'?/span>Parmprint.mat/'都不?/span>
例:(x)caffe-master-20151202\caffe-master\matlab\demo\classification_demo.m,  im = imread('../../examples/images/cat.jpg');
----------------------------------------------------------------------
  想编一个@环,每个文g名依ơ是1Q?Q等到num
for i =1:num
    savefile = [num2str(i),'.mat'];
    save(savefile, 'trainIdx', 'testIdx');%trainIdx 和testIdx 可以是其他Q何变?br />end

save的名字中含有数?/span>
ratio = 0.01;
savefile = ['NFL_ASLAN',num2str(ratio),'.mat'];
save(savefile, 'accuracy');
见我的matlab教材P20 


Python path
If I put Homework2Q2.py in another content(目录) and I use the "E:\OneDrive - ustc.edu\Lecture\ustc\Artificial intelligence related\Machine learning\Umich\..."in line 4, there is an error as follows:
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 30-31: truncated \uXXXX escape
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:
(1) r'E:\OneDrive - ustc.edu\Lecture\ustc\Artificial intelligence related\Machine learning\Umich\...'
(2) use / rather than \


杰哥 2012-06-20 21:07 发表评论
]]> ŷһþþþþþô| þ޹ӰԺվ | þҹɫƷŷ| þƵվ| ҹƷþ| www.þ99| þѾDzݲƷ| ˾Ʒһþþ| ɫ8þ97㽶987| þûƵ| þþƷ91þۺ鶹 | þþƷ޾Ʒ2020| þþƷһ| ŷպľþ| þ˿ྫƷĻ| þۺϾþۺϾþۺ| ޳ɫwwwþվҹ| ?VþþƷ| ŷ޹Ʒþѿ| þþþһƷɫ| ޹պۺϾþþƷ| þþƷһ| 91þþƷƵ| þer99ȾƷһ| ޹һ˾þþƷ| Ļþһ| þþþ޾Ʒ˵| þþƷһ| ԭƷ99þþƷ66| þþþ߽ۺϳ| þþƷ18| Ʒþˬۺ| aëƬþѲ| þԭƷ| ٸ޾þþþþ| þþþAVۺ| þþþø߳ëƬȫ| Ļձ޾þþ | ŷպƷþþѹۿ| պŮ18վþþƷ| Ʒŷһþþ|