Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancing/fixing numpy and sympy examples #17

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
19 changes: 8 additions & 11 deletions snippets_submenus_python/numpy.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,31 @@ define([
'x = np.linspace(0, 1, 7)',
'y = np.linspace(0, 1, 11)',
'xx, yy = np.meshgrid(x, y)',
'xx, yy',
],
},
{
'name' : 'Return views of the data, split into $N$ groups',
'snippet' : [
'x = np.arange(12)',
'a,b,c = np.split(x, 3)',
'a, b, c',
],
},
{
'name' : 'Return views of the data, split at given indices along given axis',
'snippet' : [
'x = np.arange(27).reshape((3,9))',
'a,b,c = np.split(x, [2,6], axis=1)',
'a, b, c',
],
},
{
'name' : 'Return copy of arrays, combined into one',
'snippet' : [
'a = np.arange(30).reshape((2,3,5))',
'b = np.arange(42).reshape((2,3,7))',
'c = np.concatenate((a, b), axis=1)',
'np.concatenate((a, b), axis=2)',
],
},
],
Expand Down Expand Up @@ -109,15 +112,15 @@ define([
'name' : 'View real array as complex',
'snippet' : [
'r = np.linspace(0, 10, num=100).reshape((25,4))',
'c = r.view(complex)',
'r.view(complex)',
],
},
{
'name' : 'View complex array as real with extra dimension',
'snippet' : [
'c = (np.linspace(0, 10, num=50) + 1j*np.linspace(0, 10, num=50))',
'cv = c.view(float)',
'r = cv.reshape(c.shape + (2,))',
'cv.reshape(c.shape + (2,))',
],
},
],
Expand Down Expand Up @@ -151,21 +154,15 @@ define([
'snippet' : [
'x = np.arange(12)',
'a,b,c = np.split(x, 3)',
'a, b, c',
],
},
{
'name' : 'Return views of the data, split at given indices along given axis',
'snippet' : [
'x = np.arange(27).reshape((3,9))',
'a,b,c = np.split(x, [2,6], axis=1)',
],
},
{
'name' : 'Return copy of arrays, combined into one',
'snippet' : [
'a = np.arange(30).reshape((2,3,5))',
'b = np.arange(42).reshape((2,3,7))',
'c = np.concatenate((a, b), axis=1)',
'a, b, c',
],
},
],
Expand Down
6 changes: 3 additions & 3 deletions snippets_submenus_python/numpy_polynomial.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ define({
{
'name' : 'Get coefficients (constant at index 0, higher indices for higher orders)',
'snippet' : [
'poly.coeff',
'poly.coef',
],
},
{
Expand Down Expand Up @@ -121,8 +121,8 @@ define({
'np.random.seed(11)',
'x = np.linspace(0, 2*np.pi, 20)',
'y = np.sin(x) + np.random.normal(scale=.1, size=x.shape)',
'n = 5',
'p = T.fit(x, y, n)',
'n = 5 # degree',
'np.polyfit(x, y, n)',
],
},
],
Expand Down
21 changes: 14 additions & 7 deletions snippets_submenus_python/numpy_ufuncs.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ define({
{
'name' : 'trace: Return the sum along diagonals of the array.',
'snippet' : [
'np.trace(a, axis1, axis2)',
'data = np.array([[3, 0, 0], [7, -1, 0], [-1, 0, 1]])',
'np.trace(data, axis1 = 0, axis2 = 1)',
],
},

Expand Down Expand Up @@ -139,28 +140,34 @@ define({
{
'name' : 'gradient: Gradient of an N-dimensional array',
'snippet' : [
'np.gradient(f, *varargs, **kwargs)',
'xx = np.arange(0, 1, 0.1)',
'yy = xx**2 + 1',
'np.gradient(yy, 0.1)',
],
},

{
'name' : 'trapz: Integrate along the given axis using the composite trapezoidal rule',
'name' : 'trapz: Integrate using the composite trapezoidal rule',
'snippet' : [
'np.trapz(y, x, dx, axis)',
'xx = np.linspace(0, np.pi, num=100)',
'yy = np.sin(xx)',
'np.trapz(yy, x=xx)',
],
},

{
'name' : 'convolve: Discrete, linear convolution of two one-dimensional sequences',
'snippet' : [
'np.convolve(a, v)',
'np.convolve([1, 2, 3], [0, 1, 0.5])',
],
},

{
'name' : 'interp: One-dimensional linear interpolation',
'snippet' : [
'np.interp(x, xp, fp)',
'xp = [-1, 2.5, 3, 8]',
'fp = [0, 4, 4.1, 5]',
'np.interp([0, 1, 2, 3, 4], xp, fp)',
],
},
],
Expand Down Expand Up @@ -955,7 +962,7 @@ define({
{
'name' : 'cross: Cross product of two (arrays of) vectors',
'snippet' : [
'np.cross(a, b)',
'np.cross([1, -1, 1], [2, 3, -6])',
],
},
],
Expand Down
4 changes: 2 additions & 2 deletions snippets_submenus_python/scipy.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ define([
'x = np.arange(0, 4.0, 0.01)',
'y_0 = [-1.0 / 3**(1.0/3.0) / gamma(1.0/3.0), 1.0 / 3**(2.0/3.0) / gamma(2.0/3.0)]',
'Ai, Aip, Bi, Bip = airy(x)',
'y = odeint(func, y_0, x, rtol=1e-12, atol=1e-12) # Exact answer: (Aip, Ai)',
'y = integrate.odeint(func, y_0, x, rtol=1e-12, atol=1e-12) # Exact answer: (Aip, Ai)',
],
},
{
Expand All @@ -205,7 +205,7 @@ define([
'x = np.arange(0, 4.0, 0.01)',
'y_0 = [-1.0 / 3**(1.0/3.0) / gamma(1.0/3.0), 1.0 / 3**(2.0/3.0) / gamma(2.0/3.0)]',
'Ai, Aip, Bi, Bip = airy(x)',
'y = odeint(func, y_0, x, rtol=1e-12, atol=1e-12, Dfun=gradient) # Exact answer: (Aip, Ai)',
'y = integrate.odeint(func, y_0, x, rtol=1e-12, atol=1e-12, Dfun=gradient) # Exact answer: (Aip, Ai)',
],
},
{
Expand Down
16 changes: 8 additions & 8 deletions snippets_submenus_python/sympy_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,27 +233,27 @@ define({
},
{
'name' : 'Stirling number of the second kind',
'snippet' : ['stirling(n, k)',],
'snippet' : ['from sympy.functions.combinatorial.numbers import stirling', 'stirling(n, k)',],
},
{
'name' : 'Stirling number of the first kind',
'snippet' : ['stirling(n, k, kind=1, signed=False)',],
'snippet' : ['from sympy.functions.combinatorial.numbers import stirling', 'stirling(n, k, kind=1, signed=False)',],
},
{
'name' : 'Reduced Stirling number of the second kind',
'snippet' : ['stirling(n, k, d)',],
'snippet' : ['from sympy.functions.combinatorial.numbers import stirling', 'stirling(n, k, d)',],
},
{
'name' : 'Number of combinations of length k among n items',
'snippet' : ['nC(n, k)',],
'snippet' : ['from sympy.functions.combinatorial.numbers import nC', 'nC(n, k)',],
},
{
'name' : 'Number of permutations of length k among n items',
'snippet' : ['nP(n, k)',],
'snippet' : ['from sympy.functions.combinatorial.numbers import nP', 'nP(n, k)',],
},
{
'name' : 'Number of partitions of length k among n items',
'snippet' : ['nT(n, k)',],
'snippet' : ['from sympy.functions.combinatorial.numbers import nT', 'nT(n, k)',],
},
],
},
Expand All @@ -270,7 +270,7 @@ define({
},
{
'name' : 'Heaviside function',
'snippet' : ['Heaviside(X)',],
'snippet' : ['Heaviside(x)',],
},
{
'name' : 'Gamma, Beta and related Functions',
Expand Down Expand Up @@ -484,7 +484,7 @@ define({
},
{
'name' : 'Dirichlet eta function',
'snippet' : ['eta(s)',],
'snippet' : ['dirichlet_eta(s)',],
},
{
'name' : 'Polylogarithm function',
Expand Down