It is a pure python library for numerical computations.
Linear algebra example:
A = Matrix([[1,2],[4,9]])
print 1/A
print (A+2)*A
B = Matrix(2,2,lambda i,j: i+j**2)
Fitting
points = [(x0,y0,dy0), (x1,y1,dy1), (x2,y2,dy2), ...]
coefficients, chi2, fitting_function = fit_least_squares(points,POLYNOMIAL(2))
for x,y,dy in points:
print x, y, '~', fitting_function(x)
Solvers:
from math import sin
def f(x): return sin(x)-1+x
x0 = solve_newton(f, 0.0, ap=0.01, rp=0.01, ns=100)
print 'f(%s)=%s ~ 0' % (x0, f(x0))
(ap is target absolute precision, rp is target relative precision, ns is max number of steps)
Optimizers:
def f(x): return (sin(x)-1+x)**2
x0 = optimize_newton(f, 0.0, ap=0.01, rp=0.01, ns=100)
print 'f(%s)=%s ~ min f' % (x0, f(x0))
print 'f'(%s)=%s ~ 0' % (x0, D(f)(x0))
Statistics:
x = [random.random() for k in range(100)]
print 'mu =', mean(x)
print 'sigma =', sd(x)
print 'E[x] =', E(lambda x:x, x)
print 'E[x^2] =', E(lambda x:x2, x)
print 'E[x^3] =', E(lambda x:x3, x)
y = [random.random() for k in range(100)]
print 'corr(x,y) = ', correlation(x,y)
print 'cov(x,y) = ', covariance(x,y)
Finance:
google = YStock('GOOG')
current = google.current()
print current['price']
print current['market_cap']
for day in google.historical():
print day['date'], day['adjusted_close'], day['log_return']
Persistant Storage:
d = PersistentDictionary(path='test.sqlite')
d['key'] = 'value'
print d['key']
del d['key']
d works like a drop-in preplacement for any normal Python dictionary except that the data is stored in a sqlite database in a file called "test.sqlite" so it is still there if you re-start the program. Kind of like the shelve module but shelve files cannot safely be accessed by multiple threads/processes unless locked and locking the entire file is not efficient.
Neural Network:
pat = [[[0,0], [0]], [[0,1], [1]], [[1,0], [1]], [[1,1], [0]]]
n = NeuralNetwork(2, 2, 1)
n.train(pat)
n.test(pat)
[0, 0] -> [0.00...]
[0, 1] -> [0.98...]
[1, 0] -> [0.98...]
[1, 1] -> [-0.00...]
Plotting:
data = [(x0,y0), ...]
Canvas(title='my plot').plot(data, color='red').save('myplot.png')
Supported languages:
.NET, Adobe Air, Android, Cold Fusion, Drupal, Go, iOS, Java, JavaScript, Python, macOS, Nancy, Node.js, PHP, Ruby on Rails, Unity, WordPress
Closed-source server backend
https://airbrake.io/languages :
Ruby, Rails, Java, Javascript, Magento, Php, .NET, Python, Django, Node.js, Swift, Android, Go, Sinatra, Angularjs, Flask, Ember, Express, Hapi
Open-source server backend of Airbrake (which has a closed-source backend)
"PEP509 added a private version number... every dictionary has a version number, and elsewhere in memory a master version counter. And when you go and change a dictionary the master counter is incremented from a million to a million and one, and that value a million and one is written into the version number of that dictionary. So what this means is that you can come back later and know if it's been modified, without reading maybe its hundreds of keys and values: you just look and see if the version has increased since the last time you were there."
-
"Ansible is simple, which is a major strength", it "works by connecting to a server using SSH, copies the Python code over, executes it and then removes itself".
"Ansible Tower is the Enterprise version, it turns the command line Ansible into a service, with a web interface, scheduler and notification system."
"you can’t have long-running tasks." -
"StackStorm is designed as a highly-configurable if-this-then-that service. it can react to events and then run a simple command or a complex workflow."
"MongoDB can be scaled using well-documented patterns." "StackStorm extensibility system is a key strength." "If StackStorm were a programming language, it would be strongly typed." -
"Salt was born as a distributed remote execution system used to execute commands and query data on remote nodes."
"Ultra high-performance for large deployments." (LinkedIn use it)
- Internal and external hyperlinks
- Automatic module reload
- Run demos
What do you think of the following innocuous Python code ?
from gevent import monkey
monkey.patch_all(thread=False, select=False)
import requests
requests.get('http://i-do-not-exist.com')
print('THIS WILL NEVER BE PRINTED !!!')
Guess what ? The string message will never get printed :(
Simply remove the monkey.patch_all
line and you'll …
Une courte présentation que j'ai donné cette après-midi à Voyages-sncf.com Technologies :
Les slides sont accessibles ici en plein écran.
Last week, my father asked me if I could find make a backup of an old lovely voicemail message he had.
I wrote a short Python script to accomplis this:
twiml_url = 'https://handler.twilio.com/twiml/EH9515e9e0d2fb81f27d75a493225ae703'
client = Client(os.environ['TWILIO_ACCOUNT_SID'], os.environ['TWILIO_AUTH_TOKEN'])
client.calls.create(to='+33241XXXXXX …
Exemple d'utilisation en notebook Python:
Sujet : http://www.xavierdupre.fr/app/ensae_teaching_cs/helpsphinx3/notebooks/TD2A_eco_API_SNCF.html
Corrigé: https://github.com/sdpython/ensae_teaching_cs/blob/master/_doc/notebooks/td2a_eco/TD2A_eco_API_SNCF_corrige.ipynb
In this blog post, I'm going to demonstrate how to reuse WiseMapping HTML+JS rendering engine to easily visualize...
text-based mindmaps like this one have many benefits they are readable as-it-is they don't require any tool to be edited they follow the UNIX tenets
For the impatient ones, here is …
This week I wrote a small Python script, that can generate a mindmap from a simple indented text input like this:
Winter december january february Spring march april may Summer june july august Autumn september october november
The command: ./graphviz_mindmap.py seasons.txt
.
The results, with various layout
parameters:
Another …
Due to a long standing bug, no history file will be kept of the commands you enter in an interactive shell when using a Python 3 virtualenv.
I found out a simple workaround. Simply put the following in your ~/.pythonrc
:
import atexit, os, readline, sys
if sys.version_info >= (3, 0 …
En mars dernier, j'ai participé à la Battledev de RegionJobs.
Et c'était super fun.
Pour ceux qui ne connaissent pas, c'est une compétition de programmation en ligne, où l'on doit résoudre 5 questions de difficulté croissante en 2 heures.
J'ai eu l'occasion d'y participer avec quelques collègues, et ça a …
Last week, I made up a basic TCP server in Python, to receive log lines. To split log lines, I used the ascii line feed ascii character : \n aka 0xa in hexadecimal.
But then I wondered : could this byte appear elsewhere in the UTF8-encoded strings of text I was sending …
Le mois dernier j'ai rapidement présenté le language Python et les frameworks web existants à mon équipe à Voyages-Sncf.com.
Les slides sont accessibles ici, ainsi que les sources Markdown pour Reveal.js.
Il …
Python generators are awesome. Why ?
- their syntax is simple an concise
- they lazily generate values and hence are very memory efficient
- bonus point: since Python 3 you can chain them with
yield from
Their drawback ? They can be iterated only once, and they hide the iterable length.
I took an …