User Tools

Site Tools


python

Python Examples

Note David Roundy prefers to keep track of which package a command is coming from… therefore

import numpy as np
a1 = np.array([1,2,3,4])

For less typing, you can do

from numpy import *
a1 = array([1,2,3,4])

Numerical integration of Gaussian

from pylab import *
a1 = array([1])
pi*a1

array([ 3.14159265])

x = arange(0,10,1)
x

array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

y = exp(-x**2)
y

array([ 1.00000000e+00, 3.67879441e-01, 1.83156389e-02, 1.23409804e-04, 1.12535175e-07, 1.38879439e-11, 2.31952283e-16, 5.24288566e-22, 1.60381089e-28, 6.63967720e-36])

sum(y)

1.3863186024133263

show(plot(y))
python.txt · Last modified: 2019/09/09 21:20 by ethanminot