<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Numpy on shocksolution.com</title><link>https://shocksolution.com/tags/numpy/</link><description>Recent content in Numpy on shocksolution.com</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Wed, 17 Aug 2011 22:40:14 +0000</lastBuildDate><atom:link href="https://shocksolution.com/tags/numpy/index.xml" rel="self" type="application/rss+xml"/><item><title>Removing an axis or both axes from a matplotlib plot</title><link>https://shocksolution.com/posts/removing-an-axis-or-both-axes-from-a-matplotlib-plot/</link><pubDate>Wed, 17 Aug 2011 22:40:14 +0000</pubDate><guid>https://shocksolution.com/posts/removing-an-axis-or-both-axes-from-a-matplotlib-plot/</guid><description>&lt;p&gt;Sometimes, the frame around a &lt;a href="http://matplotlib.sourceforge.net/" title="matplotlib"&gt;matplotlib&lt;/a&gt; plot can detract from the information you are trying to convey.  How do you remove the frame, ticks, or axes from a matplotlib plot? &lt;figure class="ma0 w-75"&gt;&lt;img src="https://shocksolution.com/images/plot_without_y_axis.png"&#10;&#9;&#9;&#9;alt="matplotlib plot without a y axis"&gt;&lt;figcaption&gt;&#10;&#9;&#9;&#9;&lt;p&gt;matplotlib plot without a y axis&lt;/p&gt;&#10;&#9;&#9;&lt;/figcaption&gt;&#10;&lt;/figure&gt;&#10;&lt;/p&gt;&#10;&lt;p&gt;Some books you may find useful when working with matplotlib: &lt;a href="https://%3C%3Cwww.amazon.com/gp/product/0132269937/ref=as_li_tl?ie=UTF8&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=0132269937&amp;amp;linkCode=as2&amp;amp;tag=rootwork0f-20&amp;amp;linkId=44971fe03f445ae25fecb2cc2702d3aa&amp;amp;gt%3E;"&gt;&lt;img src="//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;MarketPlace=US&amp;amp;ASIN=0132269937&amp;amp;ServiceVersion=20070822&amp;amp;ID=AsinImage&amp;amp;WS=1&amp;amp;Format=_SL160_&amp;amp;tag=rootwork0f-20" alt="image"&gt;&lt;/a&gt;&lt;img src="//ir-na.amazon-adsystem.com/e/ir?t=rootwork0f-20&amp;amp;l=am2&amp;amp;o=1&amp;amp;a=0132269937" alt="image"&gt;&lt;a href="https://%3C%3Cwww.amazon.com/Python-Data-Analysis-Wrangling-IPython/dp/1491957662/ref=as_li_ss_il?keywords=matplotlib&amp;amp;qid=1537646489&amp;amp;sr=8-12&amp;amp;ref=sr_1_12&amp;amp;linkCode=li2&amp;amp;tag=rootwork0f-20&amp;amp;linkId=545b965f9a5ae1055ae778fca7628568&amp;amp;language=en_US&amp;amp;gt%3E;"&gt;&lt;img src="//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;ASIN=1491957662&amp;amp;Format=_SL160_&amp;amp;ID=AsinImage&amp;amp;MarketPlace=US&amp;amp;ServiceVersion=20070822&amp;amp;WS=1&amp;amp;tag=rootwork0f-20&amp;amp;language=en_US" alt="image"&gt;&lt;/a&gt;&lt;img src="https://ir-na.amazon-adsystem.com/e/ir?t=rootwork0f-20&amp;amp;language=en_US&amp;amp;l=li2&amp;amp;o=1&amp;amp;a=1491957662" alt="image"&gt;&lt;a href="https://%3C%3Cwww.amazon.com/Mastering-matplotlib-Duncan-M-McGreggor/dp/1783987545/ref=as_li_ss_il?keywords=matplotlib&amp;amp;qid=1537646489&amp;amp;sr=8-1&amp;amp;ref=sr_1_1&amp;amp;linkCode=li2&amp;amp;tag=rootwork0f-20&amp;amp;linkId=ec917748d4c441f93e36024379f32b58&amp;amp;language=en_US&amp;amp;gt%3E;"&gt;&lt;img src="//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;ASIN=1783987545&amp;amp;Format=_SL160_&amp;amp;ID=AsinImage&amp;amp;MarketPlace=US&amp;amp;ServiceVersion=20070822&amp;amp;WS=1&amp;amp;tag=rootwork0f-20&amp;amp;language=en_US" alt="image"&gt;&lt;/a&gt;&lt;img src="https://ir-na.amazon-adsystem.com/e/ir?t=rootwork0f-20&amp;amp;language=en_US&amp;amp;l=li2&amp;amp;o=1&amp;amp;a=1783987545" alt="image"&gt;&lt;a href="https://%3C%3Cwww.amazon.com/Matplotlib-Plotting-Cookbook-Alexandre-Devert/dp/1849513260/ref=as_li_ss_il?keywords=matplotlib&amp;amp;qid=1537646489&amp;amp;sr=8-2&amp;amp;ref=sr_1_2&amp;amp;linkCode=li2&amp;amp;tag=rootwork0f-20&amp;amp;linkId=6b7d2e5dacde0fa357c7d0316befb29b&amp;amp;language=en_US&amp;amp;gt%3E;"&gt;&lt;img src="//ws-na.amazon-adsystem.com/widgets/q?_encoding=UTF8&amp;amp;ASIN=1849513260&amp;amp;Format=_SL160_&amp;amp;ID=AsinImage&amp;amp;MarketPlace=US&amp;amp;ServiceVersion=20070822&amp;amp;WS=1&amp;amp;tag=rootwork0f-20&amp;amp;language=en_US" alt="image"&gt;&lt;/a&gt;&lt;img src="https://ir-na.amazon-adsystem.com/e/ir?t=rootwork0f-20&amp;amp;language=en_US&amp;amp;l=li2&amp;amp;o=1&amp;amp;a=1849513260" alt="image"&gt;&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://github.com/cfinch/Shocksolution_Examples/tree/master/Plotting/matplotlib" title="Removing%20an%20axis%20from%20a%20Matplotlib%20plot"&gt;The full example is available on github&lt;/a&gt;.&lt;/p&gt;&#10;&lt;p&gt;First, we construct a figure and an axes object:&lt;/p&gt;&#10;&lt;div class="code-block"&gt;&#10; &lt;button class="code-copy" type="button" hidden aria-label="Copy code to clipboard"&gt;&#10; &lt;span class="code-copy-label" aria-hidden="true"&gt;Copy&lt;/span&gt;&#10; &lt;/button&gt;&#10; &lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;fig1 = plt.figure(facecolor=&amp;#39;white&amp;#39;)&#10;&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ax1 = plt.axes(frameon=False)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#10; &lt;/div&gt;&lt;p&gt;The Axes object is a container that holds the axes, the ticks, the labels, the plot, the legend, etc.  You will always have an Axes object, even if the axes are not visible! The keyword argument &lt;strong&gt;frameon=False&lt;/strong&gt; turns the frame off. An alternative method is:&lt;/p&gt;</description></item><item><title>Storing large Numpy arrays on disk: Python Pickle vs. HDF5</title><link>https://shocksolution.com/posts/storing-large-numpy-arrays-on-disk-python-pickle-vs-hdf5adsf/</link><pubDate>Sun, 10 Jan 2010 23:00:20 +0000</pubDate><guid>https://shocksolution.com/posts/storing-large-numpy-arrays-on-disk-python-pickle-vs-hdf5adsf/</guid><description>&lt;p&gt;&lt;a href="https://shocksolution.com/2008/09/15/python-pickle-painless-binary-storage-for-python-objects/" title="Python%20data%20storage%20with%20Pickle"&gt;In a previous post, I described how Python&amp;rsquo;s Pickle module is fast and convenient&lt;/a&gt; for storing all sorts of data on disk. More recently, I showed &lt;a href="https://shocksolution.com/2009/04/17/profiling-memory-usage-of-python-code/" title="Profiling%20Python%20code"&gt;how to profile the memory usage of Python code&lt;/a&gt;.  In recent weeks, I&amp;rsquo;ve uncovered a serious limitation in the Pickle module when storing large amounts of data: Pickle requires a large amount of memory to save a data structure to disk. Fortunately, there is an open standard called HDF, which defines a binary file format that is designed to efficiently store large scientific data sets. I will demonstrate both approaches, and profile them to see how much memory is required. I am writing the HDF file using the PyTables interface. Here&amp;rsquo;s the little test program I&amp;rsquo;ve been using: [code language=&amp;ldquo;Python&amp;rdquo;]#!/usr/bin/env python from numpy import array&lt;/p&gt;</description></item><item><title>Optimizing Python code for fast math</title><link>https://shocksolution.com/posts/optimizing-python-code-for-fast-math/</link><pubDate>Fri, 09 Jan 2009 21:14:38 +0000</pubDate><guid>https://shocksolution.com/posts/optimizing-python-code-for-fast-math/</guid><description>&lt;p&gt;I spent some time today profiling a Brownian dynamics simulation written in Python to see how I could make it faster before starting some long runs on a Linux cluster. In the sections below, I have attempted to quantify the speed improvements due to various changes. Keep in mind that the actual speed improvement in your code will vary, depending on where the actual bottlenecks occur. See my post about &lt;a href="https://shocksolution.com/2008/10/24/profiling-python-code/" title="Profiling%20Python%20code"&gt;profiling Python code&lt;/a&gt;. Another caveat: I am running Python 2.4.4 because it&amp;rsquo;s installed on our cluster.&lt;/p&gt;</description></item><item><title>A lookup table for fast Python math</title><link>https://shocksolution.com/posts/a-lookup-table-for-fast-python-math/</link><pubDate>Thu, 11 Dec 2008 23:17:06 +0000</pubDate><guid>https://shocksolution.com/posts/a-lookup-table-for-fast-python-math/</guid><description>&lt;p&gt;Numerical programming frequently requires the use of look-up tables. A look-up table is a collection of pre-computed values. When given an &amp;ldquo;x&amp;rdquo; value, the table returns a pre-computed &amp;ldquo;y&amp;rdquo; value. Look-up tables can be used to speed up numerical codes, when it is faster to look up a value in the table than it is to compute the value. They are also used when the data in the table cannot be computed&amp;ndash;for example, experimental data or averaged results from an ensemble of Monte Carlo simulations. Another application is to compute a value when a function cannot be solved algebraically. Assume that you have a formula for a function q(h). You need the value of h for a given value of q, but the formula cannot be algebraically solved to get h(q). Instead, choose a range of h values, compute the function q(h), and store each value in a look-up table. Now you can get h(q) for any value stored in the table. The major limitation of a look-up table is that it cannot return valid results for any value of q which is outside the range of those stored in the table. Depending on its implementation, the table may be able to interpolate to return values between known points.&lt;/p&gt;</description></item><item><title>Installing numpy with the Intel Math Kernel Library (mkl)</title><link>https://shocksolution.com/posts/installing-numpy-with-the-intel-math-kernel-library-mkl/</link><pubDate>Fri, 19 Sep 2008 21:24:58 +0000</pubDate><guid>https://shocksolution.com/posts/installing-numpy-with-the-intel-math-kernel-library-mkl/</guid><description>&lt;p&gt;Today I installed numpy on a cluster. Normally, as a Gentoo admin, I just install things with emerge, and all the details are taken care of automagically. However, this cluster runs Red Hat Enterprise, and I don&amp;rsquo;t have admin privileges, so I had to install numpy in my home directory. I installed 1.0.4, to match the version used on another system. You may not need to do this for more recent versions of numpy, which may have an improved setup script. The overall process is:&lt;/p&gt;</description></item></channel></rss>