{"id":377,"date":"2019-02-06T17:20:22","date_gmt":"2019-02-07T01:20:22","guid":{"rendered":"https:\/\/gantovnik.com\/bio-tips\/?p=377"},"modified":"2019-02-06T17:20:22","modified_gmt":"2019-02-07T01:20:22","slug":"python-example","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2019\/02\/python-example\/","title":{"rendered":"Python Example"},"content":{"rendered":"","protected":true},"excerpt":{"rendered":"","protected":true},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_lmt_disableupdate":"yes","_lmt_disable":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-377","post","type-post","status-publish","format-standard","post-password-required","hentry","category-python"],"modified_by":null,"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-65","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":139,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/multidimensional-spline\/","url_meta":{"origin":377,"position":0},"title":"Multidimensional Spline","author":"gantovnik","date":"2019-01-04","format":false,"excerpt":"import os import matplotlib.pyplot as plt import numpy as np from scipy import interpolate os.chdir(r'D:\\data\\scripts\\web1\\ex29') os.getcwd() np.random.seed(115925231) x = y = np.linspace(-1, 1, 100) X, Y = np.meshgrid(x, y) def f(x, y): return np.exp(-x**2 - y**2) * np.cos(4*x) * np.sin(6*y) Z = f(X, Y) N = 500 xdata = np.random.uniform(-1,\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example29","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example29.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example29.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example29.png?resize=525%2C300 1.5x"},"classes":[]},{"id":283,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/perceptron-model\/","url_meta":{"origin":377,"position":1},"title":"Perceptron model","author":"gantovnik","date":"2019-01-21","format":false,"excerpt":"","rel":"","context":"In &quot;machine learning&quot;","block_context":{"text":"machine learning","link":"https:\/\/gantovnik.com\/bio-tips\/category\/machine-learning\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example52.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example52.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example52.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":379,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/02\/find-nearest-value-in-numpy-array\/","url_meta":{"origin":377,"position":2},"title":"#54 Find nearest value in numpy array","author":"gantovnik","date":"2019-02-07","format":false,"excerpt":"","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":101,"url":"https:\/\/gantovnik.com\/bio-tips\/2018\/12\/solution-of-system-of-nonlinear-equations\/","url_meta":{"origin":377,"position":3},"title":"Solution of system of nonlinear equations","author":"gantovnik","date":"2018-12-31","format":false,"excerpt":"import os import matplotlib.pyplot as plt import numpy as np import scipy os.chdir('\/home\/vg\/Downloads\/projects\/ex17') os.getcwd() def f(x): return [x[1]-x[0]**3-2*x[0]**2+1,x[1]+x[0]**2-1] tol=0.1 a,b=-2,2 x=np.linspace(-3,2,5000) y1=x**3+2*x**2-1 y2=-x**2+1 fig,ax=plt.subplots(figsize=(8,4)) ax.plot(x,y1,'k',lw=1.5) ax.plot(x,y2,'k',lw=1.5) sol1=scipy.optimize.fsolve(f,[-2,2]) sol2=scipy.optimize.fsolve(f,[1,-1]) sol3=scipy.optimize.fsolve(f,[-2,-5]) sols=[sol1,sol2,sol3] colors=['r','b','g'] for idx,s in enumerate(sols): ax.plot(s[0],s[1],colors[idx]+'*',markersize=15) for m in np.linspace(-4,3,80): for n in np.linspace(-20,20,40): x_guess=[m,n] sol=scipy.optimize.fsolve(f,x_guess) idx = (abs(sols-sol)**2).sum(axis=1).argmin() ax.plot(x_guess[0],x_guess[1],colors[idx]+'.')\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example17","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example17.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example17.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2018\/12\/example17.png?resize=525%2C300 1.5x"},"classes":[]},{"id":2175,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/05\/425-an-animation-of-a-bouncing-ball-using-python\/","url_meta":{"origin":377,"position":4},"title":"#425 An animation of a bouncing ball using python","author":"gantovnik","date":"2024-05-05","format":false,"excerpt":"","rel":"","context":"In &quot;animation&quot;","block_context":{"text":"animation","link":"https:\/\/gantovnik.com\/bio-tips\/category\/animation\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/05\/ex425-1.gif?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/05\/ex425-1.gif?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/05\/ex425-1.gif?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":190,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/coupled-damped-springs-jacobian-is-available\/","url_meta":{"origin":377,"position":5},"title":"Coupled damped springs (Jacobian is available)","author":"gantovnik","date":"2019-01-10","format":false,"excerpt":"\u00a0 import os import numpy as np import matplotlib.pyplot as plt from scipy import integrate os.chdir(r'D:\\projects\\wordpress\\ex38') os.getcwd() def f(t, y, args): m1, k1, g1, m2, k2, g2 = args return [y[1], - k1\/m1 * y[0] + k2\/m1 * (y[2] - y[0]) - g1\/m1 * y[1], y[3], - k2\/m2 * (y[2]\u2026","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example38","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example38.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example38.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example38.png?resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/377","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/comments?post=377"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/377\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}