tag:blogger.com,1999:blog-48646966554540477632024-03-12T19:18:58.224-07:00Personal TechGAUTAMhttp://www.blogger.com/profile/08540129991806040616noreply@blogger.comBlogger5125tag:blogger.com,1999:blog-4864696655454047763.post-4043129928282015702018-06-07T17:33:00.001-07:002018-07-20T23:52:19.835-07:00Getting every nth line from file <div dir="ltr" style="text-align: left;" trbidi="on">
I had a problem recently where I wanted to extract every 5th line from file and I knew that every 10 lines data points to same 10 keys<br />
<br />
<br />
awk 'NR%5 == 0' file.txt<br />
<br />
gave me that<br />
<br />
<br />
<br />
<br />
In general if we want to extract every nth line from file with repeated section of length L<br />
<br />
we can just do<br />
<br />
<br />
<br />
<br />
awk 'NR%L == n' file.txt <br />
<br />
<br />
<br />
Assume that we have lines with every section of 5 lines <br />
awk 'NR%5 == 1' values | awk '{n += $1}; END{print n}' # sum of every 1st line<br />awk 'NR%5 == 2' values | awk '{n += $1}; END{print n}' # sum of every 2nd line <br />
awk 'NR%5 == 3' values | awk '{n += $1}; END{print n}' # sum of every 3rd line <br />awk 'NR%5 == 4' values | awk '{n += $1}; END{print n}' # sum of every 4th line <br />awk 'NR%5 == 0' values | awk '{n += $1}; END{print n}' # sum of every 5th line <br /><br />
<br /></div>
GAUTAMhttp://www.blogger.com/profile/08540129991806040616noreply@blogger.com0tag:blogger.com,1999:blog-4864696655454047763.post-53247804048981168612018-06-01T18:05:00.000-07:002018-06-01T18:05:36.033-07:00How to prepend text to all files in a directory<div dir="ltr" style="text-align: left;" trbidi="on">
find ./ -type f | xargs sed -i '1i wget https://repo.continuum.io/archive/Anaconda3-5.1.0-Linux-x86_64.sh \<br />chmod +x Anaconda3-5.1.0-Linux-x86_64.sh \<br />./Anaconda3-5.1.0-Linux-x86_64.sh -b \<br />source ~/.bashrc' $1<br /><br /><br /><br />find ./ -type f #Give all the files<br />
xargs # run thefollowing command<br />
$1 #will be the file path<br />
<br /></div>
GAUTAMhttp://www.blogger.com/profile/08540129991806040616noreply@blogger.com0tag:blogger.com,1999:blog-4864696655454047763.post-80411301846979991662018-04-28T01:08:00.001-07:002018-04-28T01:08:10.620-07:00How I tuned existing model to recognize custome image on mxnet<div dir="ltr" style="text-align: left;" trbidi="on">
<br /></div>
GAUTAMhttp://www.blogger.com/profile/08540129991806040616noreply@blogger.com0tag:blogger.com,1999:blog-4864696655454047763.post-55486790548976310332017-10-29T16:22:00.001-07:002018-04-28T01:07:20.741-07:00Deep Learning personal notes<div dir="ltr" style="text-align: left;" trbidi="on">
1. For Gradient descent the initialization of weight could be anything including zero, since function is convex it will always converge to <global or local?> minima<br />
<br />
2. How to check if the pytorch has mkl or not ?<br />
>>> torch.has_mkl<br />True </div>
GAUTAMhttp://www.blogger.com/profile/08540129991806040616noreply@blogger.com0tag:blogger.com,1999:blog-4864696655454047763.post-73336292234164675932015-12-09T15:23:00.001-08:002015-12-09T15:23:38.889-08:00Using pickle to se/de-rialize in python.<div dir="ltr" style="text-align: left;" trbidi="on">
<pre dir="ltr" id="CA-4432c9c973c553ebd06665a3edc404c23544eb46" lang="en"><span class="line"><span class="LineNumber"> </span><span class="LineAnchor" id="CA-4432c9c973c553ebd06665a3edc404c23544eb46_1"></span><span class="anchor" id="line-1-2"></span><span class="Comment"># Save a dictionary into a pickle file.</span></span>
<span class="line"><span class="LineNumber"> </span><span class="LineAnchor" id="CA-4432c9c973c553ebd06665a3edc404c23544eb46_2"></span><span class="anchor" id="line-2-1"></span><span class="ResWord">import</span> <span class="ID">pickle</span></span>
<span class="line"><span class="LineNumber"> </span><span class="LineAnchor" id="CA-4432c9c973c553ebd06665a3edc404c23544eb46_4"></span><span class="anchor" id="line-4-1"></span><span class="ID">favorite_color</span> = { <span class="String">"</span><span class="String">lion</span><span class="String">"</span>: <span class="String">"</span><span class="String">yellow</span><span class="String">"</span>, <span class="String">"</span><span class="String">kitty</span><span class="String">"</span>: <span class="String">"</span><span class="String">red</span><span class="String">"</span> }</span>
<span class="line"><span class="LineNumber"></span></span><span class="line"><span class="LineNumber"></span><span class="LineAnchor" id="CA-4432c9c973c553ebd06665a3edc404c23544eb46_6"></span><span class="anchor" id="line-6-1"></span><span class="ID"> pickle</span>.<span class="ID">dump</span>( <span class="ID">favorite_color</span>, <span class="ResWord">open</span>( <span class="String">"</span><span class="String">save.p</span><span class="String">"</span>, <span class="String">"</span><span class="String">wb</span><span class="String">"</span> ) )</span>
</pre>
<span class="anchor" id="line-16"></span><div class="line867">
<span class="anchor" id="line-17"></span><span class="anchor" id="line-18"></span><span class="anchor" id="line-19"></span><span class="anchor" id="line-20"></span><span class="anchor" id="line-21"></span><span class="anchor" id="line-22"></span><span class="anchor" id="line-1-3"></span></div>
<div class="highlight python">
<div class="codearea" dir="ltr" lang="en">
<br />
<pre dir="ltr" id="CA-10a60777cc6a4f82f809e00de9efde0d29c23f9f" lang="en"><span class="line"><span class="LineNumber"> </span><span class="LineAnchor" id="CA-10a60777cc6a4f82f809e00de9efde0d29c23f9f_1"></span><span class="anchor" id="line-1-4"></span><span class="Comment"># Load the dictionary back from the pickle file.</span></span>
<span class="line"><span class="LineNumber"> </span><span class="LineAnchor" id="CA-10a60777cc6a4f82f809e00de9efde0d29c23f9f_2"></span><span class="anchor" id="line-2-2"></span><span class="ResWord">import</span> <span class="ID">pickle</span></span>
<span class="line"><span class="LineNumber"> </span><span class="LineAnchor" id="CA-10a60777cc6a4f82f809e00de9efde0d29c23f9f_3"></span><span class="anchor" id="line-3-2"></span></span>
<span class="line"><span class="LineNumber"> </span><span class="LineAnchor" id="CA-10a60777cc6a4f82f809e00de9efde0d29c23f9f_4"></span><span class="anchor" id="line-4-2"></span><span class="ID">favorite_color</span> = <span class="ID">pickle</span>.<span class="ID">load</span>( <span class="ResWord">open</span>( <span class="String">"</span><span class="String">save.p</span><span class="String">"</span>, <span class="String">"</span><span class="String">rb</span><span class="String">"</span> ) )</span>
<span class="line"><span class="LineNumber"> </span><span class="LineAnchor" id="CA-10a60777cc6a4f82f809e00de9efde0d29c23f9f_5"></span><span class="anchor" id="line-5-2"></span><span class="Comment"># favorite_color is now { "lion": "yellow", "kitty": "red" }</span></span>
</pre>
</div>
</div>
</div>
GAUTAMhttp://www.blogger.com/profile/08540129991806040616noreply@blogger.com0