-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.xml
266 lines (266 loc) · 50.4 KB
/
search.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>01背包问题</title>
<url>/sublog.github.io/2020/08/14/01%E8%83%8C%E5%8C%85%E9%97%AE%E9%A2%98/</url>
<content><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\sublog.github.io\css\APlayer.min.css"><script src="\sublog.github.io\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="\sublog.github.io\js\Meting.min.js"></script>
<div id="aplayer-IMGcIstT" class="aplayer aplayer-tag-marker meting-tag-marker"
data-id="1383205688" data-server="netease" data-type="song" data-mode="circulation" data-autoplay="false" data-mutex="true" data-listmaxheight="340px" data-preload="auto" data-theme="#FF4081"
></div>
<p>朴素的 动规的 基本表示:</p>
<p>f[ i ] [ j ] : 表示只看前 i 个物品,总体积是 j 的情况下,总价值最大是多少</p>
<p>result = max[ f [ n ] [ 0 ~ V ] ]</p>
<p>f[i] [j] = </p>
<p>1.不选第 i 个物品: f[i] [j] = f[i - 1] [j];</p>
<p>2.选第 i个物品: f[i] [j] = f[i - 1] [j - v[i]];</p>
<p>f[i] [j] = max{1,2}</p>
<h4 id="例题"><a href="#例题" class="headerlink" title="例题"></a>例题</h4><p><img src= "/sublog.github.io/img/loading.gif" data-src="https://i.loli.net/2020/08/14/SkbKBvhHP7amWzg.png" alt="B5R6RE09MI_9_WU2_F_J_ZK.png"></p>
<p><img src= "/sublog.github.io/img/loading.gif" data-src="https://i.loli.net/2020/08/14/SED74quUPfajYOw.png" alt=""></p>
<figure class="highlight c++"><table><tr><td class="code"><pre><span class="line"><span class="comment">//板子板子</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> N = <span class="number">1010</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> n,m;</span><br><span class="line"><span class="keyword">int</span> f[N][N];</span><br><span class="line"><span class="keyword">int</span> v[N],w[N];</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="built_in">cin</span> >> n >> m;</span><br><span class="line"> <span class="comment">//小白想检验一下生成的f数组是不是全0数组</span></span><br><span class="line"> <span class="comment">// for(int j = 0;j < n;j++) cout<<f[j][4];</span></span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">1</span>;i <= n;i++)</span><br><span class="line"> {</span><br><span class="line"> <span class="built_in">cin</span> >> v[i] >> w[i];</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">//下面这个循环是 依次考虑 当第i个物品时,体积j依次增大,直到大于v[i]时,即当前可以装下第i个物品,即拥有了第i个物品的价值。下面进行降维优化时,j从最大体积m依次减小考虑情况。</span></span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">1</span>;i <= n;i++)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j = <span class="number">1</span>;j <= m;j++)</span><br><span class="line"> {</span><br><span class="line"> f[i][j] = f[i - <span class="number">1</span>][j];</span><br><span class="line"> <span class="keyword">if</span>(j >= v[i])</span><br><span class="line"> {</span><br><span class="line"> f[i][j] = <span class="built_in">max</span>(f[i][j],f[i - <span class="number">1</span>][j - v[i]] + w[i]);</span><br><span class="line"> <span class="comment">//小白手动跑了一遍检验发现 f[n][m]已经是最大的价值 因为赋值时进行了选择 </span></span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">// int res = 0;</span></span><br><span class="line"> <span class="comment">// for(int i = 0;i <= m;i++)</span></span><br><span class="line"> <span class="comment">// {</span></span><br><span class="line"> <span class="comment">// res = max(res,f[n][i]);</span></span><br><span class="line"> <span class="comment">// }</span></span><br><span class="line"> <span class="built_in">cout</span><<f[n][m]<<<span class="built_in">endl</span>;</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<figure class="highlight c++"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> N = <span class="number">1010</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> n,m;</span><br><span class="line"><span class="keyword">int</span> f[N]; <span class="comment">//这里进行降维优化</span></span><br><span class="line"><span class="keyword">int</span> v[N],w[N];</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="built_in">cin</span> >> n >> m;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">1</span>;i <= n;i++)</span><br><span class="line"> {</span><br><span class="line"> <span class="built_in">cin</span> >> v[i] >> w[i];</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">1</span>;i <= n;i++)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j = m;j >= v[i];j--)</span><br><span class="line"> {</span><br><span class="line"> <span class="comment">//由于此时变成了一位数组 由于比较的是和它前一位f[i-1][j-v[i]]为了更好地表示发生变化,我们应选择体积从最大的体积m依次递减</span></span><br><span class="line"> f[j] = <span class="built_in">max</span>(f[j],f[j - v[i]] + w[i]);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">cout</span><<f[m]<<<span class="built_in">endl</span>;</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
]]></content>
<categories>
<category>ACwing</category>
</categories>
<tags>
<tag>背包</tag>
</tags>
</entry>
<entry>
<title>My first blog</title>
<url>/sublog.github.io/2020/03/13/My-first-blog/</url>
<content><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\sublog.github.io\css\APlayer.min.css"><script src="\sublog.github.io\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="\sublog.github.io\js\Meting.min.js"></script>
<div id="aplayer-sZtmwqXZ" class="aplayer aplayer-tag-marker meting-tag-marker"
data-id="2919622" data-server="netease" data-type="song" data-mode="circulation" data-autoplay="false" data-mutex="true" data-listmaxheight="340px" data-preload="auto" data-theme="#FF4081"
></div>
<h2 id="位运算"><a href="#位运算" class="headerlink" title="位运算"></a>位运算</h2><figure class="highlight c"><table><tr><td class="code"><pre><span class="line"><span class="comment">//熄灯问题</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><iostream></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><cstring></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">char</span> old[<span class="number">10</span>], lights[<span class="number">10</span>], result[<span class="number">10</span>]; <span class="comment">//原数组,灯数组,结果数组</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">SetBit</span><span class="params">(<span class="keyword">char</span> &c, <span class="keyword">int</span> i, <span class="keyword">int</span> v)</span> <span class="comment">//c代表第i行的字符,把第i行的第j位设置成v</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">if</span>(v) {</span><br><span class="line"> c = c | (<span class="number">1</span> << i);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> </span><br><span class="line"> c = c & ~(<span class="number">1</span> << i);</span><br><span class="line">}</span><br><span class="line"><span class="comment">//v = 1</span></span><br><span class="line"><span class="comment">//如果把第3位上的设置为1</span></span><br><span class="line"><span class="comment">//0010 0101 </span></span><br><span class="line"><span class="comment">//0010 0101 | 0000 1000 = 0010 1101 按位或运算</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//v = 0</span></span><br><span class="line"><span class="comment">//如果把第2位上的位设置为0</span></span><br><span class="line"><span class="comment">//0010 0101</span></span><br><span class="line"><span class="comment">//~(1 << 2)= ~(0000 0100) = (1111 1011)</span></span><br><span class="line"><span class="comment">//0010 0101 & 1111 1011 = 0010 0001</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">GetBit</span><span class="params">(<span class="keyword">char</span> c, <span class="keyword">int</span> i)</span> <span class="comment">//取出c的第i位上的数字</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">return</span> (c >> i) & <span class="number">1</span>;</span><br><span class="line">}</span><br><span class="line"><span class="comment">//0010 0001 右移3位 0000 0100 & 0000 0001 = 0</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">FilpBit</span><span class="params">(<span class="keyword">char</span> &c, <span class="keyword">int</span> i)</span> <span class="comment">//翻转c的第i位</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> c = c ^ (<span class="number">1</span> << i);</span><br><span class="line">}</span><br><span class="line"><span class="comment">//0010 0101</span></span><br><span class="line"><span class="comment">//翻转第3位上的数字</span></span><br><span class="line"><span class="comment">//0010 0101 ^ 0000 1000 = 0010 1101</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">OutPutResult</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>; i < <span class="number">5</span>; ++i)</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j = <span class="number">0</span>; j < <span class="number">6</span>; ++j) {</span><br><span class="line"> <span class="built_in">cout</span> << GetBit(result[i], j);</span><br><span class="line"> <span class="keyword">if</span>(j < <span class="number">5</span>) <span class="built_in">cout</span> << <span class="string">" "</span>;</span><br><span class="line"> <span class="keyword">else</span> <span class="built_in">cout</span> << <span class="built_in">endl</span>;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">int</span> kase;</span><br><span class="line"> <span class="built_in">cin</span>>>kase;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">1</span>;i <= kase ;i++)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">int</span> v, switchs;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>; i < <span class="number">5</span>; ++i)</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j = <span class="number">0</span>; j < <span class="number">6</span>; ++j) {</span><br><span class="line"> <span class="built_in">cin</span> >> v;</span><br><span class="line"> SetBit(old[i], j, v);</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> n = <span class="number">0</span>; n < <span class="number">1</span> << <span class="number">6</span>; ++n) { <span class="comment">//6个开关,2的6次方种情况, (1 << 6 == 2^6)</span></span><br><span class="line"> <span class="built_in">memcpy</span>(lights, old, <span class="keyword">sizeof</span>(old)); <span class="comment">//还原lights数组</span></span><br><span class="line"> switchs = n;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>; i < <span class="number">5</span>; ++i) {</span><br><span class="line"> result[i] = switchs; <span class="comment">// 0 0 1 0 1 0</span></span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j = <span class="number">0</span>; j < <span class="number">6</span>; ++j) {</span><br><span class="line"> <span class="keyword">if</span>(GetBit(switchs, j)) {</span><br><span class="line"> <span class="keyword">if</span>(j > <span class="number">0</span>) FilpBit(lights[i], j - <span class="number">1</span>); <span class="comment">//翻转左边</span></span><br><span class="line"> FilpBit(lights[i], j); <span class="comment">//翻转本身</span></span><br><span class="line"> <span class="keyword">if</span>(j < <span class="number">5</span>) FilpBit(lights[i], j + <span class="number">1</span>); <span class="comment">//翻转右边</span></span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(i < <span class="number">4</span>) lights[i + <span class="number">1</span>] ^= switchs;</span><br><span class="line"> switchs = lights[i];</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(lights[<span class="number">4</span>] == <span class="number">0</span>) {</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"PUZZLE #%d\n"</span>,i);</span><br><span class="line"> OutPutResult();</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
]]></content>
</entry>
<entry>
<title>Hello World</title>
<url>/sublog.github.io/2020/03/13/hello-world/</url>
<content><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\sublog.github.io\css\APlayer.min.css"><script src="\sublog.github.io\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="\sublog.github.io\js\Meting.min.js"></script><p>Welcome to <a href="https://hexo.io/" target="_blank" rel="noopener">Hexo</a>! This is your very first post. Check <a href="https://hexo.io/docs/" target="_blank" rel="noopener">documentation</a> for more info. If you get any problems when using Hexo, you can find the answer in <a href="https://hexo.io/docs/troubleshooting.html" target="_blank" rel="noopener">troubleshooting</a> or you can ask me on <a href="https://github.com/hexojs/hexo/issues" target="_blank" rel="noopener">GitHub</a>.</p>
<h2 id="Quick-Start"><a href="#Quick-Start" class="headerlink" title="Quick Start"></a>Quick Start</h2><h3 id="Create-a-new-post"><a href="#Create-a-new-post" class="headerlink" title="Create a new post"></a>Create a new post</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">$ hexo new <span class="string">"My New Post"</span></span><br></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/writing.html" target="_blank" rel="noopener">Writing</a></p>
<h3 id="Run-server"><a href="#Run-server" class="headerlink" title="Run server"></a>Run server</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">$ hexo server</span><br></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/server.html" target="_blank" rel="noopener">Server</a></p>
<h3 id="Generate-static-files"><a href="#Generate-static-files" class="headerlink" title="Generate static files"></a>Generate static files</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">$ hexo generate</span><br></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/generating.html" target="_blank" rel="noopener">Generating</a></p>
<h3 id="Deploy-to-remote-sites"><a href="#Deploy-to-remote-sites" class="headerlink" title="Deploy to remote sites"></a>Deploy to remote sites</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">$ hexo deploy</span><br></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/one-command-deployment.html" target="_blank" rel="noopener">Deployment</a></p>
]]></content>
<categories>
<category>note</category>
</categories>
<tags>
<tag>tip</tag>
</tags>
</entry>
<entry>
<title>os --第一章 操作系统引论</title>
<url>/sublog.github.io/2020/07/11/os%E7%AC%AC%E4%B8%80%E7%AB%A0/</url>
<content><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\sublog.github.io\css\APlayer.min.css"><script src="\sublog.github.io\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="\sublog.github.io\js\Meting.min.js"></script><h4 id="操作系统的目标和作用"><a href="#操作系统的目标和作用" class="headerlink" title="操作系统的目标和作用"></a>操作系统的目标和作用</h4><p> 定义: ==os==是直接控制和管理计算机硬件、软件资源,合理地对各类作业进行调度,以方便用户使用的==程序集合==</p>
<p> 地位:系统硬件之上,所有其他软件之下</p>
<p> 目标:</p>
<ul>
<li>方便性 (如果没有os,c语言程序无法运行)</li>
<li>有效性</li>
<li>可扩充性</li>
</ul>
<h5 id="发展过程"><a href="#发展过程" class="headerlink" title="发展过程"></a>发展过程</h5>]]></content>
<categories>
<category>复习</category>
</categories>
<tags>
<tag>操作系统</tag>
</tags>
</entry>
<entry>
<title>python review--01</title>
<url>/sublog.github.io/2020/08/26/python-review-01/</url>
<content><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\sublog.github.io\css\APlayer.min.css"><script src="\sublog.github.io\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="\sublog.github.io\js\Meting.min.js"></script><h4 id="对象和变量"><a href="#对象和变量" class="headerlink" title="对象和变量"></a>对象和变量</h4><h5 id="1-一切都是对象"><a href="#1-一切都是对象" class="headerlink" title="1.一切都是对象"></a>1.一切都是对象</h5><p>所有的对象都具有三个特征:</p>
<ul>
<li><p>身份</p>
<p>每一个对象唯一身份标识,可以使用内建函数id( )查看,所得到的值也可以认为是该对象的内存地址。</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">a = b = 34</span><br><span class="line">id(x) = id(y)</span><br></pre></td></tr></table></figure>
<p>引用计数</p>
</li>
<li><p>类型</p>
<p><img src= "/sublog.github.io/img/loading.gif" data-src="https://i.loli.net/2020/08/26/GTIvx7t9y8ZCHej.png" alt="image-20200826104012089"></p>
<p>b继承a</p>
<p>类型可以通过type( )方法来查看类型,</p>
<figure class="highlight"><table><tr><td class="code"><pre><span class="line"><span class="comment">#以字符串形式输出它的类型名字</span></span><br><span class="line">type('a') -->str</span><br><span class="line">type(str).__name__ -->'type'</span><br></pre></td></tr></table></figure>
<p>使用 isinstance ( )方法来验证类型</p>
<figure class="highlight"><table><tr><td class="code"><pre><span class="line">isinstance(object,classinfo)</span><br><span class="line"><span class="comment">#参数</span></span><br><span class="line">object --实例对象</span><br><span class="line">classinfo --可以直接或间接类名,基本类型或者由它们组成的元组</span><br><span class="line"></span><br><span class="line">isinstance(3,int) --> True</span><br><span class="line">isinstance(3.7,(str,float,int)) -->True</span><br></pre></td></tr></table></figure>
</li>
<li><p>值 操作符:< > <= >= == != <> 返回值:布尔值</p>
</li>
</ul>
<h5 id="2-变量"><a href="#2-变量" class="headerlink" title="2.变量"></a>2.变量</h5><p>变量,是在程序中为了方便引用内存中的值而为它所取的名字。</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 增量赋值,与C语言中的算数自反赋值运算一样</span></span><br><span class="line">int_example *= <span class="number">3</span></span><br><span class="line">string_example += <span class="string">'Try it!'</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 多重赋值</span></span><br><span class="line">x = y = z = <span class="number">1</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 多元赋值,很有用,用起来效率很高,括号是可选的,但保留可以增强代码可读性</span></span><br><span class="line">(x, y, z) = (<span class="number">1</span>, <span class="number">2</span>, <span class="string">'a string'</span>)</span><br><span class="line"></span><br><span class="line">(x, y) = (y, x) <span class="comment"># 对x, y的值做交换,不需要第三个辅助变量了</span></span><br></pre></td></tr></table></figure>
<p>变量名 标识符</p>
<p>1.命名规则:只能包含 小写字母,大写字母,下划线,数字,且不能以数字开头,<strong>python以下划线开头的名字有特殊含义。</strong></p>
<p>2.关键字</p>
<p>3.builtins 进入解释器时,builtins模块自动导入,一般情况下,定义的标识符不要冲突。</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">import</span> builtins</span><br><span class="line">dir(builtins) <span class="comment">#参数为对象、变量、类型 返回模块的属性列表</span></span><br><span class="line"></span><br><span class="line">dir() <span class="comment">#返回当前模块属性列表</span></span><br><span class="line">dir( [ ]) <span class="comment">#查看列表的方法</span></span><br></pre></td></tr></table></figure>
<figure class="highlight"><table><tr><td class="code"><pre><span class="line">a = <span class="number">90</span></span><br><span class="line">b = <span class="number">90</span></span><br><span class="line">a <span class="keyword">is</span> b</span><br><span class="line">-->True #连等就是True,不连等就是False 整数小于256都是True</span><br></pre></td></tr></table></figure>
<h4 id="数字"><a href="#数字" class="headerlink" title="数字"></a>数字</h4><p>注意:</p>
<p> 浮点数除法:/ 两个整数进行运算时,还会得到浮点型结果</p>
<p> 整数除法: //</p>
<p>数字可以直接访问,是不可更改并且不可分割的原子类型。 不可更改意味着变更数字值的实质是新对象的创建。</p>
<h5 id="更新数字对象:创建了新的对象,然后让变量指向新的对象"><a href="#更新数字对象:创建了新的对象,然后让变量指向新的对象" class="headerlink" title="更新数字对象:创建了新的对象,然后让变量指向新的对象"></a>更新数字对象:创建了新的对象,然后让变量指向新的对象</h5><h5 id="删除数字对象:-del-变量名"><a href="#删除数字对象:-del-变量名" class="headerlink" title="删除数字对象: del 变量名"></a>删除数字对象: del 变量名</h5><p>注意:注意引用计数与对象之间</p>
<h4 id="布尔值"><a href="#布尔值" class="headerlink" title="布尔值"></a>布尔值</h4><p>事实上,布尔型是整型的子类,对应整型1和0</p>
<h5 id="布尔运算:-优先级由高到低:not-,and-,-or"><a href="#布尔运算:-优先级由高到低:not-,and-,-or" class="headerlink" title="布尔运算: 优先级由高到低:not ,and , or"></a>布尔运算: 优先级由高到低:not ,and , or</h5><p>要善于运用括号避免问题</p>
<h4 id="复数"><a href="#复数" class="headerlink" title="复数"></a>复数</h4><p>real + imag j 注意:虚数部分结尾是j 或 J</p>
<p>real 实数部分,imag虚数部分,还有一个方法,conjugate( ),用来获取共轭复数。</p>
<figure class="highlight"><table><tr><td class="code"><pre><span class="line">a_complex = <span class="number">3.5</span> + <span class="number">2.9</span> j</span><br><span class="line">a_complex.real --> 3.5</span><br><span class="line">a_complex.imag --> 2.9</span><br><span class="line">a_complex.conjugate() --> (3.5-2.9j)</span><br></pre></td></tr></table></figure>
<h4 id="基数"><a href="#基数" class="headerlink" title="基数"></a>基数</h4><p>0b 或者 0B表示二进制 0b10 —>2</p>
<p>0o 或者 0O表示八进制 0o10 —>8</p>
<p>0x 或者 0X表示十六进制 0x10 —>16</p>
<h5 id="类型转换:转换失败会产生ValueError异常。"><a href="#类型转换:转换失败会产生ValueError异常。" class="headerlink" title="类型转换:转换失败会产生ValueError异常。"></a>类型转换:转换失败会产生<code>ValueError</code>异常。</h5><p>基本规则:整型转换为浮点型,非复数转换为复数。总之,简单类型向复杂类型转换,不精确向更精确类型转换。</p>
<ul>
<li><code>int()</code></li>
<li><code>float()</code></li>
<li><code>complex()</code></li>
<li><code>bool()</code></li>
</ul>
<h5 id="功能函数:"><a href="#功能函数:" class="headerlink" title="功能函数:"></a>功能函数:</h5><p>abs( ) : 返回绝对值,如果参数是整型,返回整型,如果是浮点型,返回浮点类型, 同样也可用于复数绝对值的计算,即返回实部和虚部平方和的二次方根。</p>
<figure class="highlight"><table><tr><td class="code"><pre><span class="line">abs(3 +4j) --> 5.0</span><br><span class="line">abs(4.5) --> 4.5</span><br><span class="line">abs(-3) --> 3</span><br></pre></td></tr></table></figure>
<p>divmod ( ) : 此函数将除法和求余结合起来,返回一个包含商和余数的元组.</p>
<figure class="highlight"><table><tr><td class="code"><pre><span class="line">divmod(2.5,10) --> (0.0,2.5)</span><br><span class="line">divmod(10,3) --> (3,1)</span><br></pre></td></tr></table></figure>
<p>pow ( ) : 幂运算 传两个参数</p>
<p>round ( ) : 做真正的四舍五入!可以用第二个参数指定精确到小数点后第几位:</p>
<figure class="highlight"><table><tr><td class="code"><pre><span class="line">round(4.499) -> 4</span><br><span class="line">round(4.6) -> 5</span><br><span class="line">round(4.51) -> 5</span><br><span class="line">round(4.492,2)-> 4.49</span><br><span class="line">round(4.499,2)-> 4.5</span><br></pre></td></tr></table></figure>
<h4 id="字符串"><a href="#字符串" class="headerlink" title="字符串"></a>字符串</h4><p>字符串由一系列Unicode码位组成的不可变序列</p>
<p>使用内建函数<code>len()</code>可以获得字符串长度</p>
<p>不可变指无法对字符串本身进行更改操作</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line">s = <span class="string">'a'</span><span class="string">'b'</span></span><br><span class="line">s</span><br><span class="line">---> 'ab'</span><br><span class="line"></span><br><span class="line"><span class="comment">#常见的转义符:`\n`(换行符)、`\t`(Tab制表符)、`\'`(单引号)、`\"`(双引号)、`\\`(反斜线)</span></span><br></pre></td></tr></table></figure>
<h5 id="内建函数"><a href="#内建函数" class="headerlink" title="内建函数"></a>内建函数</h5><figure class="highlight python"><table><tr><td class="code"><pre><span class="line">input( ) <span class="comment">#获取用户输入,返回字符串</span></span><br><span class="line">chr( ) <span class="comment">#接收一个整数,返回对应的Unicode字符</span></span><br><span class="line">ord( ) <span class="comment">#功能与chr( )相反</span></span><br></pre></td></tr></table></figure>
]]></content>
<tags>
<tag>python</tag>
</tags>
</entry>
<entry>
<title>page</title>
<url>/sublog.github.io/2020/06/03/page/</url>
<content><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\sublog.github.io\css\APlayer.min.css"><script src="\sublog.github.io\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="\sublog.github.io\js\Meting.min.js"></script>]]></content>
</entry>
<entry>
<title>leetcode03.数组中重复的数字-1</title>
<url>/sublog.github.io/2020/07/22/leetcode03-%E6%95%B0%E7%BB%84%E4%B8%AD%E9%87%8D%E5%A4%8D%E7%9A%84%E6%95%B0%E5%AD%97/</url>
<content><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\sublog.github.io\css\APlayer.min.css"><script src="\sublog.github.io\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="\sublog.github.io\js\Meting.min.js"></script>
<div id="aplayer-cUgtjviA" class="aplayer aplayer-tag-marker meting-tag-marker"
data-id="1434062381" data-server="netease" data-type="song" data-mode="circulation" data-autoplay="false" data-mutex="true" data-listmaxheight="340px" data-preload="auto" data-theme="#FF4081"
></div>
<h4 id="题目描述:"><a href="#题目描述:" class="headerlink" title="题目描述:"></a>题目描述:</h4><p>找出数组中重复的数字。</p>
<p>在一个长度为 n 的数组 nums 里的所有数字都在 0~n-1 的范围内。数组中某些数字是重复的,但不知道有几个数字重复了,也不知道每个数字重复了几次。请找出数组中任意一个重复的数字。</p>
<h5 id="示例"><a href="#示例" class="headerlink" title="示例"></a>示例</h5><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">输入:</span><br><span class="line">[2, 3, 1, 0, 2, 5, 3]</span><br><span class="line">输出:2 或 3</span><br></pre></td></tr></table></figure>
<h5 id="限制:2-lt-n-lt-100000"><a href="#限制:2-lt-n-lt-100000" class="headerlink" title="限制:2 <= n <= 100000"></a>限制:2 <= n <= 100000</h5><h4 id="思路:"><a href="#思路:" class="headerlink" title="思路:"></a>思路:</h4><p>==方法一:遍历数组==</p>
<p> 遍历整个数组,找到任意一个重复的数字,即返回。且当为了判断一个数字是否重复遇到,使用集合存储已经遇到的数字,如果遇到的数字已经在集合中,则当前的数字是重复数字。</p>
<ul>
<li><p>时间复杂度:O(n)。</p>
<pre><code>遍历数组一遍。使用哈希集合(HashSet),添加元素的时间复杂度为 O(1),故总的时间复杂度是 O(n)。
</code></pre></li>
<li><p>空间复杂度:O(n)。</p>
<p> 不重复的每个元素都可能存入集合,因此占用 O(n) 额外空间。</p>
</li>
</ul>
<h4 id="Java语言版本"><a href="#Java语言版本" class="headerlink" title="Java语言版本"></a>Java语言版本</h4><figure class="highlight java"><table><tr><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Solution</span> </span>{</span><br><span class="line"> <span class="function"><span class="keyword">public</span> <span class="keyword">int</span> <span class="title">findRepeatNumber</span><span class="params">(<span class="keyword">int</span>[] nums)</span> </span>{</span><br><span class="line"> Set<Integer> set = <span class="keyword">new</span> HashSet<Integer>(); </span><br><span class="line"> <span class="comment">//数组中已遍历的要存入的集合</span></span><br><span class="line"> <span class="keyword">int</span> repeat = -<span class="number">1</span>; <span class="comment">//如果找到重复的返回值</span></span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> num : nums) { </span><br><span class="line"> <span class="keyword">if</span> (!set.add(num)) { <span class="comment">//如果放入集合失败,则查找到重复的</span></span><br><span class="line"> repeat = num;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> repeat;</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p>==方法二:哈希表冲突(修改数组)==</p>
<p> 由题意可以看出:<strong><em>数组 nums 里的所有数字都在 0~n-1 的范围内</em></strong></p>
<p> 那么可以,将下标与数组中的值一一对应。即看到数值,就知道它应该在下标对应的位置,即数字num[i]应该放在 i 的位置上,这就像数据结构中人为编写的哈希函数。而重复的数即哈希冲突。</p>
<p>算法流程:</p>
<ul>
<li>遍历数组 nums ,设索引初始值为 i = 0:<br>若 nums[i] == i : 说明此数字已在对应索引位置,无需交换,因此执行 i += 1 与 continue ;<pre><code> 若 nums[nums[i]] == nums[i] : 说明索引 nums[i] 处的元素值也为 nums[i],即找到一组相同值,返回此值 nums[i];
否则: 当前数字是第一次遇到,因此交换索引为 i 和 nums[i] 的元素值,将此数字交换至对应索引位置。
</code></pre></li>
<li>若遍历完毕尚未返回,则返回 -1,代表数组中无相同值。</li>
</ul>
<p>复杂度分析:</p>
<ul>
<li>时间复杂度:O(N),这里 N 是数组的长度。虽然 for 循环里面套了 while,但是每一个数来到它应该在的位置以后,位置就不会再变化。这里用到的是均摊复杂度分析的方法:如果在某一个位置 while 循环体执行的次数较多,那么一定在后面的几个位置,根本不会执行 while 循环体内的代码,也就是说最坏的情况不会一直出现。也就是说最坏复杂度的情况不会一直出现。</li>
<li>空间复杂度:O(1)。</li>
</ul>
<h4 id="Python语言版本"><a href="#Python语言版本" class="headerlink" title="Python语言版本"></a>Python语言版本</h4><figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Solution</span>:</span></span><br><span class="line"> <span class="function"><span class="keyword">def</span> <span class="title">findRepeatNumber</span><span class="params">(self, nums: [int])</span> -> int:</span></span><br><span class="line"> i = <span class="number">0</span></span><br><span class="line"> <span class="keyword">while</span> i < len(nums):</span><br><span class="line"> <span class="keyword">if</span> nums[i] == i: //值在它该在的位置上</span><br><span class="line"> i += <span class="number">1</span></span><br><span class="line"> <span class="keyword">continue</span></span><br><span class="line"> <span class="keyword">if</span> nums[nums[i]] == nums[i]: <span class="keyword">return</span> nums[i] //哈希冲突</span><br><span class="line"> nums[nums[i]], nums[i] = nums[i], nums[nums[i]] //交换</span><br><span class="line"> <span class="keyword">return</span> <span class="number">-1</span></span><br></pre></td></tr></table></figure>
]]></content>
<categories>
<category>剑指offer</category>
</categories>
<tags>
<tag>leetcode</tag>
</tags>
</entry>
<entry>
<title>完全背包问题</title>
<url>/sublog.github.io/2020/08/20/%E5%AE%8C%E5%85%A8%E8%83%8C%E5%8C%85%E9%97%AE%E9%A2%98/</url>
<content><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\sublog.github.io\css\APlayer.min.css"><script src="\sublog.github.io\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="\sublog.github.io\js\Meting.min.js"></script>
<div id="aplayer-YRilEFlZ" class="aplayer aplayer-tag-marker meting-tag-marker"
data-id="1463165983" data-server="netease" data-type="song" data-mode="circulation" data-autoplay="false" data-mutex="true" data-listmaxheight="340px" data-preload="auto" data-theme="#FF4081"
></div>
<h4 id="01背包问题是:每件物品只能选或不选"><a href="#01背包问题是:每件物品只能选或不选" class="headerlink" title="01背包问题是:每件物品只能选或不选"></a>01背包问题是:每件物品只能选或不选</h4><h4 id="完全背包问题是:每件物品有无限件可用"><a href="#完全背包问题是:每件物品有无限件可用" class="headerlink" title="完全背包问题是:每件物品有无限件可用"></a>完全背包问题是:每件物品有无限件可用</h4><p>例题:</p>
<p><img src= "/sublog.github.io/img/loading.gif" data-src="https://i.loli.net/2020/08/20/wsXD8SQ96LdvRcm.png" alt="image-20200820142308586"></p>
<p><img src= "/sublog.github.io/img/loading.gif" data-src="https://i.loli.net/2020/08/20/uGS8ogMtPybqaOR.png" alt="image-20200820142327939"></p>
<h4 id="考虑状态表示:"><a href="#考虑状态表示:" class="headerlink" title="考虑状态表示:"></a>考虑状态表示:</h4><p>f [ i ] : 表示总体积i情况下,最大价值是多少</p>
<p>result = max{ f [ 0 . . . m ] } //m表示背包容量</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">for(int i = 0;i < n;i++)</span><br><span class="line">{</span><br><span class="line"> for(int j = v[i];j <= m;j++)//从小到大枚举</span><br><span class="line"> {</span><br><span class="line"> f[j] = max(f[j],f[j - v[i]] + w[i]);</span><br><span class="line"> }</span><br><span class="line"> //可替换成为</span><br><span class="line"> for(int j = m;j >= v[i];j--) //从大到小枚举</span><br><span class="line"> {</span><br><span class="line"> for(int k = 0;k * v[i] <= j;k++) //枚举选择的物品</span><br><span class="line"> {</span><br><span class="line"> f[j] = max(f[j],f[j - k * v[i]] + k * w[i]);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h4 id="数学归纳法:"><a href="#数学归纳法:" class="headerlink" title="数学归纳法:"></a>数学归纳法:</h4><ol>
<li>假设考虑第 i- 1个物品之后,所有的f [ j ]都是正确的</li>
<li>来证明:考虑完第 i 个物品后,所有的f [ j ] 也都是正确的</li>
</ol>
<p> 对于某个 j 来说,如果最优解包含 k 个v [ i ] ,那么一定有过这个状态</p>
<p> f [ j - k * v [ i ] ]</p>
<p>-> f [ j - k * v [ i ] - v[ i ] ] + w[i] </p>
<p>包含一个v [ i ]</p>
<p>……</p>
<p>f [ j ] f [ j - v [ i ] ] + w[ i ]</p>
<figure class="highlight c++"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> N = <span class="number">1010</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> n,m;</span><br><span class="line"><span class="keyword">int</span> f[N];</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="built_in">cin</span> >> n >> m;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>;i < n;i++)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">int</span> v,w;</span><br><span class="line"> <span class="built_in">cin</span> >> v >> w;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j = v;j <= m;j++)</span><br><span class="line"> {</span><br><span class="line"> f[j] = <span class="built_in">max</span>(f[j],f[j - v] + w);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">cout</span> << f[m] << <span class="built_in">endl</span>;</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h4 id="总结:"><a href="#总结:" class="headerlink" title="总结:"></a>总结:</h4><p>01背包与完全背包第一重循环一样</p>
<p>第二重循环时:</p>
<p>01背包从大到小枚举;</p>
<p>完全背包从小到大枚举;</p>
]]></content>
<categories>
<category>ACwing</category>
</categories>
<tags>
<tag>背包</tag>
</tags>
</entry>
<entry>
<title>花书 --应用数学与机器学习基础</title>
<url>/sublog.github.io/2020/06/25/%E8%8A%B1%E4%B9%A6-%E5%BA%94%E7%94%A8%E6%95%B0%E5%AD%A6%E4%B8%8E%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0%E5%9F%BA%E7%A1%80/</url>
<content><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\sublog.github.io\css\APlayer.min.css"><script src="\sublog.github.io\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="\sublog.github.io\js\Meting.min.js"></script>
<div id="aplayer-dfcOXzSw" class="aplayer aplayer-tag-marker meting-tag-marker"
data-id="1418175693" data-server="netease" data-type="song" data-mode="circulation" data-autoplay="false" data-mutex="true" data-listmaxheight="340px" data-preload="auto" data-theme="#FF4081"
></div>
<blockquote id="fn_top_img">
<sup>top_img</sup>. 莱辛巴赫瀑布,瑞士伯尼尔高地<a href="#reffn_top_img" title="Jump back to footnote [top_img] in the text."> ↩</a>
</blockquote>
<p><del>以下皆为本人花书的笔记</del></p>
<h3 id="标量、向量、矩阵和张量"><a href="#标量、向量、矩阵和张量" class="headerlink" title="标量、向量、矩阵和张量"></a>标量、向量、矩阵和张量</h3><p><font color="#0000dd">标量</font>:一个标量就是一个单独的数。用斜体表示标量。当我们介绍标量时,会明确它们是哪种类型的数。</p>
<p> 例:实数标量:“令<em>s</em>∈R表示一条线的斜率”;自然数标量:”令<em>n</em>∈N表示元素的数目”。</p>
<p><font color="#0000dd">向量</font>:一个向量就是一列数。这些数有序排列。通常我们赋予向量粗体小写变量名称,比如<strong>x</strong>。向量<strong>x</strong>的第一个元素x1……如果每个元素都属于R,并且该向量有n个元素,那么该向量属于实数集R的n次笛卡尔乘积构成的集合,记为Rn。当需要明确表示向量元素是,我们会将元素排列成一个方括号包围的纵列:</p>
<p><img src= "/sublog.github.io/img/loading.gif" data-src="https://i.loli.net/2020/06/25/uSeznLZmQ8RMBci.png" alt="image-20200625165749119.png"></p>
<p>当我们需要索引向量中的一些元素,我们定义一个包含这些元素索引的集合,然后将该集合写在脚标处。</p>
<p> 例:指定x1,x3,x5,定义集合S = {1,3,5},然后写作<strong>x</strong>~s~</p>
<p> 同时我们用符号_表示集合补集的索引,<strong>x</strong> _~1~表示<strong>x</strong>中除了x1外的元素,而<strong>x</strong> _~S~表示<strong>x</strong>中除了x1,x3,x5外的所有元素构成的向量。</p>
<p>==矩阵==: 二维数组。赋予粗体大写变量名称,<strong>A</strong>。A~1,1~表示左上的元素。我们通过用”:”表示水平坐标,以表示垂直坐标i中的所有元素。<strong>A</strong>~i,:~ 表示 <strong>A</strong> 中垂直坐标 <em>i</em> 上的一横排元素。这也被称为 <strong>A</strong> 的第 <em>i</em> 行(row)。<em>f</em>(<strong>A</strong>)<em>i,j</em> 表示函数 <em>f</em> 作用在 <strong>A</strong> 上输出的矩阵的第 <em>i</em> 行第 <em>j</em> 列元素。</p>
<p>==张量==: 一般地,一个数组中的元素分布在若干维坐标的规则网格中,我们称之为张量。我们使用字体 <strong>A</strong> 来表示张量 “A’’。张量 <strong>A</strong> 中坐标为 (<em>i, j, k</em>) 的元素记作 <em>A</em>~i,j,k~。</p>
<h3 id="矩阵和向量相乘"><a href="#矩阵和向量相乘" class="headerlink" title="矩阵和向量相乘"></a>矩阵和向量相乘</h3><p>==转置==:以主对角线为轴的镜像。我们将矩阵 <strong>A</strong> 的转置表示为 <strong>A</strong>^⊤^,</p>
<p> 定义如下 (<strong>A</strong>⊤<em>)</em>~i,j~ = <em>A<strong>~j,i~</strong>.</em> </p>
<ol>
<li>只要矩阵的形状一样,我们可以把两个矩阵相加。两个矩阵相加是指对应位置的元素相加,比如 <strong>C</strong> = <strong>A</strong> + <strong>B</strong>,其中 <em>C</em>~i,j~ = <em>A</em>~i,j~ + <em>B</em>~i,j~。</li>
<li>标量和矩阵相乘,或是和矩阵相加时,我们只需将其与矩阵的每个元素相乘或相加,比如 <strong>D</strong> = <em>a</em> <em>·</em> <strong>B</strong> + <em>c</em>,其中 <em>D</em>~i,j~= <em>a</em> <em>·</em> <em>B</em>~i,j~ + <em>c</em></li>
<li>在深度学习中,我们也使用一些不那么常规的符号。我们允许矩阵和向量相加,产生另一个矩阵:<strong>C</strong> = <strong>A</strong> + <strong>b</strong>,其中 <em>C</em>~i,j~ = <em>A</em>~i,j~ + <em>b</em>~j~。。这个简写方法使我们无需在加法操作前定义一个将向量 <strong>b</strong> 复制到每一行而生成的矩阵。这种隐式地复制向量 <strong>b</strong> 到很多位置的方式,被称为 广播。</li>
</ol>
<p>矩阵相乘:<img src= "/sublog.github.io/img/loading.gif" data-src="https://i.loli.net/2020/06/25/X5MsvRouW1piVBA.png" alt="image-20200625182340300.png"></p>
]]></content>
<categories>
<category>机器学习</category>
</categories>
<tags>
<tag>线性代数</tag>
</tags>
</entry>
</search>