Popular recipes tagged "numpy" but not "kinect"http://code.activestate.com/recipes/tags/numpy-kinect/2016-03-19T12:57:38-07:00ActiveState Code RecipesSaving a numpy array to png image using fitz / MuPDF (PyMuPDF) (Python) 2016-03-19T12:57:38-07:00Harald Liederhttp://code.activestate.com/recipes/users/4191581/http://code.activestate.com/recipes/580630-saving-a-numpy-array-to-png-image-using-fitz-mupdf/ <p style="color: grey"> Python recipe 580630 by <a href="/recipes/users/4191581/">Harald Lieder</a> (<a href="/recipes/tags/fitz/">fitz</a>, <a href="/recipes/tags/image/">image</a>, <a href="/recipes/tags/mupdf/">mupdf</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/png/">png</a>, <a href="/recipes/tags/pymupdf/">pymupdf</a>). Revision 2. </p> <p>If a pixel array is defined in numpy, it can be saved as a PNG image VERY fast if you use PyMuPDF.</p> Monte Carlo Engine : Stochastic Interest Rate Predictor (Python) 2014-04-27T16:42:29-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/578867-monte-carlo-engine-stochastic-interest-rate-predic/ <p style="color: grey"> Python recipe 578867 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/carlo/">carlo</a>, <a href="/recipes/tags/interest/">interest</a>, <a href="/recipes/tags/model/">model</a>, <a href="/recipes/tags/monte/">monte</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/rate/">rate</a>). Revision 2. </p> <p>This is a simple Monte Carlo Engine model, based on some ideas from the Quantopian folks. The idea is that the model and the engine are separate. I have integrated a simple example from an earlier post. The idea was to try and build some game theory simulations using simple models that were separate from the Engine. </p> Hartree Fock SCF (Python) 2013-04-30T09:09:20-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/578515-hartree-fock-scf/ <p style="color: grey"> Python recipe 578515 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/physics/">physics</a>). Revision 4. </p> <p>Quantum Chemistry technique to calculate various interesting operators for HeH.</p> Locate and see the biggest cross in a random matrix (Python) 2013-09-13T13:31:03-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/578657-locate-and-see-the-biggest-cross-in-a-random-matri/ <p style="color: grey"> Python recipe 578657 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/search/">search</a>). </p> <p>Interesting search space problem.</p> Conway's Game of Life In Python (Python) 2013-06-13T15:33:41-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/578559-conways-game-of-life-in-python/ <p style="color: grey"> Python recipe 578559 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/life/">life</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/of/">of</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/windows/">windows</a>). </p> <p>Conway's Game of Life In Python</p> How to read millions of hexadecimal numbers into a numpy array quickly (Python) 2012-06-27T06:03:40-07:00Oren Tiroshhttp://code.activestate.com/recipes/users/2033964/http://code.activestate.com/recipes/578177-how-to-read-millions-of-hexadecimal-numbers-into-a/ <p style="color: grey"> Python recipe 578177 by <a href="/recipes/users/2033964/">Oren Tirosh</a> (<a href="/recipes/tags/numpy/">numpy</a>). </p> <p>The numpy.fromfile() function supports binary formats or decimal text. How do you read millions of hexadecimal numbers quickly?</p> Coordinates of numpy array from index and shape (Python) 2012-10-23T19:51:55-07:00Garretthttp://code.activestate.com/recipes/users/4181290/http://code.activestate.com/recipes/578302-coordinates-of-numpy-array-from-index-and-shape/ <p style="color: grey"> Python recipe 578302 by <a href="/recipes/users/4181290/">Garrett</a> (<a href="/recipes/tags/convert/">convert</a>, <a href="/recipes/tags/coordinates/">coordinates</a>, <a href="/recipes/tags/index/">index</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>returns the coordinates of a numpy array given the index and the shape. A first_index_et function is given as example code</p> Fast Indexing functions (greater than, less than, equal to, and not equal to) (Python) 2012-03-13T16:21:36-07:00Garretthttp://code.activestate.com/recipes/users/4181290/http://code.activestate.com/recipes/578071-fast-indexing-functions-greater-than-less-than-equ/ <p style="color: grey"> Python recipe 578071 by <a href="/recipes/users/4181290/">Garrett</a> (<a href="/recipes/tags/index/">index</a>, <a href="/recipes/tags/list/">list</a>, <a href="/recipes/tags/list_comprehension/">list_comprehension</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/python/">python</a>). Revision 2. </p> <p>Oftentimes you want to find the index of a list-like object. Numpy arrays, for example, do not have a index member function. These get the job done quickly.</p> <p>Note: these do not raise exceptions, instead they return -1 on error. You should change that if you want different behavior.</p> Fast Sorting of n dimensional array by first dimension (Python) 2012-03-14T15:14:11-07:00Garretthttp://code.activestate.com/recipes/users/4181290/http://code.activestate.com/recipes/578074-fast-sorting-of-n-dimensional-array-by-first-dimen/ <p style="color: grey"> Python recipe 578074 by <a href="/recipes/users/4181290/">Garrett</a> (<a href="/recipes/tags/argsort/">argsort</a>, <a href="/recipes/tags/lists/">lists</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/sorting/">sorting</a>). </p> <p>I have looked far and wide for code for fast sorting of n dimensional arrays by the first element, for example if I had the array: <br /> ray = [[1,2,3,7,5][10,11,12,13,14]] </p> <p>I would want it to come out as ray = [[1,2,3,5,7][10,11,12,14,13]]</p> <p>There are several ways to do this. One is zipped = zip(<em>ray) zipped.sort() ray = zip(</em>zipped)</p> <p>but this is extremely slow. Numpy has a much faster way to do it, but it wasn't immediately apparent.</p> <p>if the above were a numpy array you could simply do the following: indexes = numpy.argsort(ray[0]) for n in xrange(len(ray)) ray[n] = ray[n][indexes]</p> <p>I did a time test of the two methods below.</p> Conversion of PIL Image and numpy array (Python) 2011-03-05T03:47:56-08:00Shao-chuan Wanghttp://code.activestate.com/recipes/users/4168519/http://code.activestate.com/recipes/577591-conversion-of-pil-image-and-numpy-array/ <p style="color: grey"> Python recipe 577591 by <a href="/recipes/users/4168519/">Shao-chuan Wang</a> (<a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/pil/">pil</a>). Revision 2. </p> <p>The utility function that converts PIL image to numpy array and vice versa.</p> Fastest way to list all primes below N in python (Python) 2010-07-27T01:57:20-07:00robert.william.hankshttp://code.activestate.com/recipes/users/4174481/http://code.activestate.com/recipes/577331-fastest-way-to-list-all-primes-below-n-in-python/ <p style="color: grey"> Python recipe 577331 by <a href="/recipes/users/4174481/">robert.william.hanks</a> (<a href="/recipes/tags/fast/">fast</a>, <a href="/recipes/tags/fastest/">fastest</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/primes/">primes</a>, <a href="/recipes/tags/python/">python</a>). Revision 6. </p> <p>I was looking for a fast way to list all primes below n, so far i came up to this with the numpy solution the fastest. It does primes up to 10e6 in 15ms in my old machine, and it is capable of reaching 10e9. </p> A fast & memory-wise prime number generator up to N (Python) 2010-08-13T18:28:00-07:00robert.william.hankshttp://code.activestate.com/recipes/users/4174481/http://code.activestate.com/recipes/577357-a-fast-memory-wise-prime-number-generator-up-to-n/ <p style="color: grey"> Python recipe 577357 by <a href="/recipes/users/4174481/">robert.william.hanks</a> (<a href="/recipes/tags/fast/">fast</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/primes/">primes</a>, <a href="/recipes/tags/prime_generator/">prime_generator</a>, <a href="/recipes/tags/prime_number/">prime_number</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>Using python 2.6 &amp; numpy. This code was first posted <a href="http://stackoverflow.com/questions/2897297/speed-up-bitstring-bit-operations-in-python/2908512#2908512">here</a></p> Incremental PCA (Python) 2010-05-01T18:04:39-07:00Micha Kalfonhttp://code.activestate.com/recipes/users/4173851/http://code.activestate.com/recipes/577213-incremental-pca/ <p style="color: grey"> Python recipe 577213 by <a href="/recipes/users/4173851/">Micha Kalfon</a> (<a href="/recipes/tags/incremental/">incremental</a>, <a href="/recipes/tags/klt/">klt</a>, <a href="/recipes/tags/learning/">learning</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/pca/">pca</a>, <a href="/recipes/tags/scipy/">scipy</a>, <a href="/recipes/tags/svd/">svd</a>, <a href="/recipes/tags/vision/">vision</a>). </p> <p>An incremental PCA algorithm in python. </p> <p>Incremental PCA allows computing an approximation of the principal components on large data sets as observations are given sequentially.</p> Infix operators for numpy arrays (Python) 2010-06-07T05:57:07-07:00John Schulmanhttp://code.activestate.com/recipes/users/4171677/http://code.activestate.com/recipes/577201-infix-operators-for-numpy-arrays/ <p style="color: grey"> Python recipe 577201 by <a href="/recipes/users/4171677/">John Schulman</a> (<a href="/recipes/tags/array/">array</a>, <a href="/recipes/tags/infix/">infix</a>, <a href="/recipes/tags/matrix/">matrix</a>, <a href="/recipes/tags/multiplication/">multiplication</a>, <a href="/recipes/tags/numpy/">numpy</a>). Revision 3. </p> <p>This recipe adapts the infix operator trick from <a href="http://code.activestate.com/recipes/384122-infix-operators/" rel="nofollow">http://code.activestate.com/recipes/384122-infix-operators/</a> to give the appropriate behavior with numpy arrays, so you can write A *dot* B for np.dot(A,B)</p> <p>UPDATE A solution to the dot problem was recently added to the numpy trunk: the dot method was added to the ndarray class so you can write a.dot(b). See <a href="http://projects.scipy.org/numpy/ticket/1456" rel="nofollow">http://projects.scipy.org/numpy/ticket/1456</a></p> Calculations on huge (memmap-)arrays (Python) 2009-05-05T10:19:37-07:00d.schlabinghttp://code.activestate.com/recipes/users/4168903/http://code.activestate.com/recipes/576739-calculations-on-huge-memmap-arrays/ <p style="color: grey"> Python recipe 576739 by <a href="/recipes/users/4168903/">d.schlabing</a> (<a href="/recipes/tags/memmap/">memmap</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/oop/">oop</a>). Revision 2. </p> <p>This is a way of doing calculations on whole arrays that might be to big to fit into memory.</p> Poor man's mgrid (Python) 2009-01-21T15:37:13-08:00David Lamberthttp://code.activestate.com/recipes/users/4167420/http://code.activestate.com/recipes/576625-poor-mans-mgrid/ <p style="color: grey"> Python recipe 576625 by <a href="/recipes/users/4167420/">David Lambert</a> (<a href="/recipes/tags/index/">index</a>, <a href="/recipes/tags/index_tricks/">index_tricks</a>, <a href="/recipes/tags/method/">method</a>, <a href="/recipes/tags/mgrid/">mgrid</a>, <a href="/recipes/tags/numerical/">numerical</a>, <a href="/recipes/tags/numerical_methods/">numerical_methods</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/scipy/">scipy</a>, <a href="/recipes/tags/trick/">trick</a>). </p> <p>Python 3 code. scipy.mgrid is a useful! This short implementation comes without installing numpy.</p> pauli spin matricies (Python) 2008-08-26T01:52:06-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/576458-pauli-spin-matricies/ <p style="color: grey"> Python recipe 576458 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/kron/">kron</a>, <a href="/recipes/tags/ladder/">ladder</a>, <a href="/recipes/tags/numpy/">numpy</a>, <a href="/recipes/tags/pauli/">pauli</a>, <a href="/recipes/tags/physics/">physics</a>, <a href="/recipes/tags/spin/">spin</a>). </p> <p>simple spin investigation in python</p>