Popular recipes tagged "meta:requires=math" but not "python"http://code.activestate.com/recipes/tags/meta:requires=math-python/2017-07-15T00:46:59-07:00ActiveState Code RecipesUno (Text-Based) (Python) 2017-07-15T00:46:59-07:00Brandon Martinhttp://code.activestate.com/recipes/users/4194238/http://code.activestate.com/recipes/580811-uno-text-based/ <p style="color: grey"> Python recipe 580811 by <a href="/recipes/users/4194238/">Brandon Martin</a> (<a href="/recipes/tags/artificial_intelligence/">artificial_intelligence</a>, <a href="/recipes/tags/cards/">cards</a>, <a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/text_game/">text_game</a>, <a href="/recipes/tags/uno/">uno</a>). </p> <p>A text based recreation of the classic card game featuring functional AIs to play with. Some rules have been modified. User interface is text based, non-curses, using only simple python commands to draw it. </p> Auto differentiation (Python) 2016-08-07T22:02:10-07:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/580610-auto-differentiation/ <p style="color: grey"> Python recipe 580610 by <a href="/recipes/users/178123/">Raymond Hettinger</a> (<a href="/recipes/tags/autodifferentiation/">autodifferentiation</a>, <a href="/recipes/tags/calculus/">calculus</a>, <a href="/recipes/tags/descent/">descent</a>, <a href="/recipes/tags/gradient/">gradient</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/optimization/">optimization</a>, <a href="/recipes/tags/vector/">vector</a>). Revision 5. </p> <p>Directly computes derivatives from ordinary Python functions using auto differentiation. The technique directly computes the desired derivatives to full precision without resorting to symbolic math and without making estimates bases on numerical methods.</p> <p>The module provides a Num class for "dual" numbers that performs both regular floating point math on a value and its derivative at the same time. In addition, the module provides drop-in substitutes for most of the functions in the math module. There are also tools for partial derivatives, directional derivatives, gradients of scalar fields, and the curl and divergence of vector fields.</p> Hopfield Artificial Neural Network (C++) 2016-07-03T21:58:49-07:00Jay ballerhttp://code.activestate.com/recipes/users/4194368/http://code.activestate.com/recipes/580688-hopfield-artificial-neural-network/ <p style="color: grey"> C++ recipe 580688 by <a href="/recipes/users/4194368/">Jay baller</a> (<a href="/recipes/tags/ai/">ai</a>, <a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/artificial_intelligence/">artificial_intelligence</a>, <a href="/recipes/tags/neural_network/">neural_network</a>). </p> <p>(Discrete (Binary)) Hopfield Artificial Neural Network (ANN).</p> <p>For more info see:</p> <p><a href="http://en.wikipedia.org/wiki/Hopfield_net" rel="nofollow">http://en.wikipedia.org/wiki/Hopfield_net</a></p> <p><a href="http://www.scholarpedia.org/article/Hopfield_network" rel="nofollow">http://www.scholarpedia.org/article/Hopfield_network</a></p> 10 lines for a beginner to try out the Spyder IDE for python programming (Python) 2015-09-18T15:04:09-07:00mai3ahttp://code.activestate.com/recipes/users/4192857/http://code.activestate.com/recipes/579100-10-lines-for-a-beginner-to-try-out-the-spyder-ide-/ <p style="color: grey"> Python recipe 579100 by <a href="/recipes/users/4192857/">mai3a</a> (<a href="/recipes/tags/error/">error</a>, <a href="/recipes/tags/snippet/">snippet</a>, <a href="/recipes/tags/spyder/">spyder</a>, <a href="/recipes/tags/stuffthatworks/">stuffthatworks</a>). </p> <p>This python code generates no lint errors and just print out a few numbers.</p> <p>Useful if you use the Spyder IDE for the first time, which provides NOTHING to get you started.</p> Garden Requirements Calculator (Python) 2014-09-17T22:04:36-07:00Ethan Hannhttp://code.activestate.com/recipes/users/4190746/http://code.activestate.com/recipes/578935-garden-requirements-calculator/ <p style="color: grey"> Python recipe 578935 by <a href="/recipes/users/4190746/">Ethan Hann</a> (<a href="/recipes/tags/calculator/">calculator</a>, <a href="/recipes/tags/garden/">garden</a>, <a href="/recipes/tags/math/">math</a>). </p> <p>This program takes input from the user and determines the amount of gardening materials needed for a garden. The garden is a perfect square. The four outer flowerbeds are congruent semicircles and the central flowerbed is a perfect circle. Everything else inside the garden is considered fill: stone, mulch, or other fill material.</p> Analog Clock (Python) 2014-05-14T20:53:39-07:00Paulo Cavalcantihttp://code.activestate.com/recipes/users/4189949/http://code.activestate.com/recipes/578875-analog-clock/ <p style="color: grey"> Python recipe 578875 by <a href="/recipes/users/4189949/">Paulo Cavalcanti</a> (<a href="/recipes/tags/clock/">clock</a>). Revision 3. </p> <p>A python-tkinter analog clock</p> Perfect Square Checker (Python) 2014-09-10T02:21:27-07:00Ethan Hannhttp://code.activestate.com/recipes/users/4190746/http://code.activestate.com/recipes/578931-perfect-square-checker/ <p style="color: grey"> Python recipe 578931 by <a href="/recipes/users/4190746/">Ethan Hann</a> (<a href="/recipes/tags/check/">check</a>, <a href="/recipes/tags/checker/">checker</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/root/">root</a>, <a href="/recipes/tags/square/">square</a>). </p> <p>This program will take input from the user and either check if a number is a perfect square or square a number, depending on user's choice.</p> Rotatable Tetrahedron (Python) 2014-05-14T21:03:40-07:00Paulo Cavalcantihttp://code.activestate.com/recipes/users/4189949/http://code.activestate.com/recipes/578876-rotatable-tetrahedron/ <p style="color: grey"> Python recipe 578876 by <a href="/recipes/users/4189949/">Paulo Cavalcanti</a> (<a href="/recipes/tags/rotatable/">rotatable</a>, <a href="/recipes/tags/tetrahedron/">tetrahedron</a>). Revision 2. </p> <p>Draws a 3D tetrahedron and allows a user to rotate it (mouse left button and wheel).</p> Gimp Paperwhite Scriptfu (Python) 2014-03-25T10:17:07-07:00Alfehttp://code.activestate.com/recipes/users/4182236/http://code.activestate.com/recipes/578857-gimp-paperwhite-scriptfu/ <p style="color: grey"> Python recipe 578857 by <a href="/recipes/users/4182236/">Alfe</a> (<a href="/recipes/tags/gimp/">gimp</a>, <a href="/recipes/tags/image_processing/">image_processing</a>, <a href="/recipes/tags/paperwhite/">paperwhite</a>, <a href="/recipes/tags/plugin/">plugin</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/scriptfu/">scriptfu</a>). </p> <p>This Gimp-plugin (written in Python) changes a photograph of a paper document so that the paper background appears white again without overly lighting the text.</p> Public Key Encryption (RSA) (Python) 2013-12-27T06:43:59-08:00Mohammad Taha Jahangirhttp://code.activestate.com/recipes/users/4188847/http://code.activestate.com/recipes/578797-public-key-encryption-rsa/ <p style="color: grey"> Python recipe 578797 by <a href="/recipes/users/4188847/">Mohammad Taha Jahangir</a> (<a href="/recipes/tags/encryption/">encryption</a>, <a href="/recipes/tags/inverse/">inverse</a>, <a href="/recipes/tags/multiplicative/">multiplicative</a>, <a href="/recipes/tags/primality_testing/">primality_testing</a>, <a href="/recipes/tags/primes/">primes</a>, <a href="/recipes/tags/publickey/">publickey</a>, <a href="/recipes/tags/rsa/">rsa</a>). Revision 3. </p> <p>Simple code to create and use public/private keypairs. Accompanied by a rudimentary encoder.</p> FreshFish (Python) 2013-12-29T15:38:33-08:00Justin Shawhttp://code.activestate.com/recipes/users/1523109/http://code.activestate.com/recipes/578800-freshfish/ <p style="color: grey"> Python recipe 578800 by <a href="/recipes/users/1523109/">Justin Shaw</a> . Revision 2. </p> <p>FreshFish is a function decorator for functions with no arguments (hardware query).</p> <p>The first time the function is called, the wrapper caches the result (the fish). Subsequent calls to the wrapped function simply return the cached result as long as the fish is still fresh. When the fish goes stale, FreshFish calls the underlying function again for FreshFish.</p> <p>I used this on a BeagleBone project to monitor heart rate, speed, and cadence.</p> Determine bytes needed to hold integer (Python3) (Python) 2013-11-03T18:35:18-08:00teddy_khttp://code.activestate.com/recipes/users/4187115/http://code.activestate.com/recipes/578766-determine-bytes-needed-to-hold-integer-python3/ <p style="color: grey"> Python recipe 578766 by <a href="/recipes/users/4187115/">teddy_k</a> (<a href="/recipes/tags/bytes/">bytes</a>, <a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/integer/">integer</a>). </p> <p>Convenience function to determine the number of bytes needed for a specified integer (split into multiple lines for clarity's sake ... could just as easily be a one-liner).</p> <p>If this is already a defined function within Python, please let me know--a quick web search turned up nothing.</p> de Polignac's Formula (Python) 2013-08-10T03:40:02-07:00Samuel James Ericksonhttp://code.activestate.com/recipes/users/4187478/http://code.activestate.com/recipes/578632-de-polignacs-formula/ <p style="color: grey"> Python recipe 578632 by <a href="/recipes/users/4187478/">Samuel James Erickson</a> (<a href="/recipes/tags/factorial/">factorial</a>, <a href="/recipes/tags/n/">n</a>, <a href="/recipes/tags/prime/">prime</a>, <a href="/recipes/tags/primes/">primes</a>). Revision 4. </p> <p>Obtains the total number of factors of p in n! for any prime p.</p> Convert from decimal to base-n for any positive n less than or equal to 10 (Python) 2013-08-09T05:56:16-07:00Samuel James Ericksonhttp://code.activestate.com/recipes/users/4187478/http://code.activestate.com/recipes/578630-convert-from-decimal-to-base-n-for-any-positive-n-/ <p style="color: grey"> Python recipe 578630 by <a href="/recipes/users/4187478/">Samuel James Erickson</a> (<a href="/recipes/tags/binary/">binary</a>, <a href="/recipes/tags/decimal/">decimal</a>, <a href="/recipes/tags/octal/">octal</a>). </p> <p>Takes in any non-negative integer and converts to the desired base-n for 1&lt;=n&lt;=10.</p> Archimedes Method for PI (arbitrary precision) (Python) 2013-03-02T21:56:42-08:00Bjorn Madsenhttp://code.activestate.com/recipes/users/4176352/http://code.activestate.com/recipes/578478-archimedes-method-for-pi-arbitrary-precision/ <p style="color: grey"> Python recipe 578478 by <a href="/recipes/users/4176352/">Bjorn Madsen</a> (<a href="/recipes/tags/decimal/">decimal</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/pi/">pi</a>, <a href="/recipes/tags/precision/">precision</a>, <a href="/recipes/tags/python3/">python3</a>). </p> <p>The code below incorporates the newly revised python 3.3.0 decimal module to permit arbitrary precision (<a href="http://docs.python.org/3/library/decimal.html%29" rel="nofollow">http://docs.python.org/3/library/decimal.html)</a></p> <p>The recipe was originally by FB35 from <a href="http://code.activestate.com/recipes/576981-archimedes-method-for-calculating-pi/" rel="nofollow">http://code.activestate.com/recipes/576981-archimedes-method-for-calculating-pi/</a> </p> Analog stopclock (Python) 2013-03-15T18:30:37-07:00prashanth.chengihttp://code.activestate.com/recipes/users/4185699/http://code.activestate.com/recipes/578493-analog-stopclock/ <p style="color: grey"> Python recipe 578493 by <a href="/recipes/users/4185699/">prashanth.chengi</a> (<a href="/recipes/tags/analog/">analog</a>, <a href="/recipes/tags/chess/">chess</a>, <a href="/recipes/tags/clock/">clock</a>). </p> <p>A very simple tkinter analog stopclock</p> Plotting maps with Polar Stereographic projection focused in a region with Basemap (Python) 2012-12-15T11:49:52-08:00PGhttp://code.activestate.com/recipes/users/4184598/http://code.activestate.com/recipes/578379-plotting-maps-with-polar-stereographic-projection-/ <p style="color: grey"> Python recipe 578379 by <a href="/recipes/users/4184598/">PG</a> (<a href="/recipes/tags/map/">map</a>, <a href="/recipes/tags/matplotlib/">matplotlib</a>, <a href="/recipes/tags/plotting/">plotting</a>, <a href="/recipes/tags/projections/">projections</a>, <a href="/recipes/tags/stereographic/">stereographic</a>). Revision 3. </p> <p>When plotting maps with either 'npstere' or 'spstere' projections with the Basemap toolkit for Matplotlib, the pole will always be placed in the center of the figure. With this function you can zoom the map to the area of interest by giving the latitude/longitudes coordinates of the bounds.</p> Human readable file/memory sizes (Python) 2012-11-05T11:59:20-08:00Tony Fluryhttp://code.activestate.com/recipes/users/4184150/http://code.activestate.com/recipes/578321-human-readable-filememory-sizes/ <p style="color: grey"> Python recipe 578321 by <a href="/recipes/users/4184150/">Tony Flury</a> (<a href="/recipes/tags/formatting/">formatting</a>, <a href="/recipes/tags/memory/">memory</a>, <a href="/recipes/tags/size/">size</a>). Revision 5. </p> <p>In writing a application to display the file sizes of set of files, I wanted to provide a human readable size rather then just displaying a byte count (which can get rather big).</p> <p>I developed this useful short recipe that extends the format specifier mini Language to add the S presentation type - which will intelligently convert the value to be displayed into a known human readable size format - i.e. b, Kb,Mb, Gb etc. It honours the rest of the format specification language (<a href="http://docs.python.org/2/library/string.html#format-string-syntax%29" rel="nofollow">http://docs.python.org/2/library/string.html#format-string-syntax)</a></p> <p>It uses a factor of 1024 at each stage</p> Position The Cursor Almost Anywhere Inside Standard Text Mode Python Terminal. (Python) 2012-06-17T17:10:29-07:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578167-position-the-cursor-almost-anywhere-inside-standar/ <p style="color: grey"> Python recipe 578167 by <a href="/recipes/users/4177147/">Barry Walker</a> (<a href="/recipes/tags/amiga/">amiga</a>, <a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/cursor/">cursor</a>, <a href="/recipes/tags/demo/">demo</a>, <a href="/recipes/tags/e_uae/">e_uae</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/locate/">locate</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/winuae/">winuae</a>). </p> <p>A DEMO showing the power of the ANSI (ASCII) _Esc_ codes in standard text mode Python.</p> <p>ANSI _Esc_ codes here:- <a href="http://www.termsys.demon.co.uk/vtansi.htm" rel="nofollow">http://www.termsys.demon.co.uk/vtansi.htm</a></p> <p>There are only three important things from the ANSI _Esc_ codes that are needed to obtain a neat finish to a program written in standard text mode Python:-</p> <p>1) Clearing the screen. (Already done without the dedicated ANSI _Esc_ code!)</p> <p>2) Colours and other character attributes. (Already done!)</p> <p>3) A forced printing of a character or string from a given location inside the Terminal window.</p> <p>To clear the screen does NOT require another dedicated ANSI _Esc_ code, (although it exists). This code uses the print("\r\n") method which works in all cases coupled with the one function supplied......</p> <p>For The Classic AMIGA, E-UAE, WinUAE and Linux using Python(s) 1.4.0 to Python 3.2.2. Read the code for more information...</p> <p>Enjoy finding simple solutions to often very difficult problems...</p> <p>Bazza, G0LCU.</p> "Effcient" Prime Number Generator in Python (Python) 2013-01-19T03:58:05-08:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578402-effcient-prime-number-generator-in-python/ <p style="color: grey"> Python recipe 578402 by <a href="/recipes/users/4184772/">Captain DeadBones</a> (<a href="/recipes/tags/prime_generator/">prime_generator</a>, <a href="/recipes/tags/prime_number/">prime_number</a>). </p> <p>This is a prime number generator in python that I put together for an article I wrote <a href="http://thelivingpearl.com/2013/01/06/how-to-find-prime-numbers-in-python/">How To Find Prime Numbers In Python</a></p> <p>Please Note. This is only efficient per the article discussing this code in the link above. See comments for a better library to generate prime numbers.</p>