Author Archives: Linuxgal

Unknown's avatar

About Linuxgal

Need a spiritual home? Consider joining us at Mary Queen of the Universe Latter-day Buddhislamic Free Will Christian UFO Synagogue of Vishnu

Linalg

Python for all your linear algebra homework: #!/usr/bin/env python3 import sys,ast,numpy as np a=np.array(ast.literal_eval(sys.argv[1])) print(“Matrix:”) print(np.matrix(a)) print(“\nTranspose:”) print(np.matrix(a.T)) print(“\nTrace:”,a.trace()) print(“\nRank:”,np.linalg.matrix_rank(a)) if a.shape[0]==a.shape[1]: print(“\nDeterminant:”,round(np.linalg.det(a),6)) d,e=np.linalg.eig(a) print(“\nEigenvalues:”,np.round(d,6)) print(“\nEigenvectors:”) print(np.round(e,6)) print(“\nPseudo-inverse:”) print(np.matrix(np.linalg.pinv(a)))

Posted in Uncategorized | Leave a comment

Italic

Convert text to italics with Python #!/usr/bin/env python3 import sys a=”ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz” b=”𝘈𝘉𝘊𝘋𝘌𝘍𝘎𝘏𝘐𝘑𝘒𝘓𝘔𝘕𝘖𝘗𝘘𝘙𝘚𝘛𝘜𝘝𝘞𝘟𝘠𝘡𝘢𝘣𝘤𝘥𝘦𝘧𝘨𝘩𝘪𝘫𝘬𝘭𝘮𝘯𝘰𝘱𝘲𝘳𝘴𝘵𝘶𝘷𝘸𝘹𝘺𝘻” print(” “.join(sys.argv[1:]).translate(str.maketrans(a,b))) #!/usr/bin/env python3 import sys c=”ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789″ b=”𝗔𝗕𝗖𝗗𝗘𝗙𝗚𝗛𝗜𝗝𝗞𝗟𝗠𝗡𝗢𝗣𝗤𝗥𝗦𝗧𝗨𝗩𝗪𝗫𝗬𝗭𝗮𝗯𝗰𝗱𝗲𝗳𝗴𝗵𝗶𝗷𝗸𝗹𝗺𝗻𝗼𝗽𝗾𝗿𝘀𝘁𝘂𝘃𝘄𝘅𝘆𝘇𝟬𝟭𝟮𝟯𝟰𝟱𝟲𝟳𝟴𝟵” print(“”.join(b[c.find(x)] if x in c else x for x in ” “.join(sys.argv[1:])))

Posted in Uncategorized | Leave a comment

Anagram

Find anagrams with Python #!/usr/bin/env python3 from collections import Counter import sys,os s=sys.argv[1] def anagrams(word,words): cw=Counter(word) return [w for w in words if Counter(w)==cw] base=os.path.dirname(os.path.abspath(__file__)) path=os.path.join(base,”words.txt”) with open(path) as f: lines=f.read().splitlines() print(anagrams(s,lines))

Posted in Uncategorized | Leave a comment

Win311

Posted in Uncategorized | Leave a comment

Quadratic

Solve quadratic equations with impunity using Python (and complex numbers) #!/usr/bin/env python3 import math,sys a,b,c=map(float,sys.argv[1:]) d=b*b-4*a*c if d>=0:x1=(-b+math.sqrt(d))/(2*a);x2=(-b-math.sqrt(d))/(2*a) else:r=-b/(2*a);i=math.sqrt(-d)/(2*a);x1,x2=complex(r,i),complex(r,-i) print(“The function has”,”two real roots: {} and {}”.format(x1,x2)if d>0 else “one double root: {}”.format(x1)if d==0 else “two complex roots: {} and … Continue reading

Posted in Uncategorized | Leave a comment

Pyble

Print the shortest and longest verses in the Bible with Python #!/usr/bin/env python3 import os base=os.path.dirname(os.path.abspath(__file__)) path=os.path.join(base,”kjv.txt”) with open(path) as f: print(“Shortest verse:”,min(f,key=len)) with open(path) as f: print(“Longest verse:”,max(f,key=len))

Posted in Uncategorized | Leave a comment

Contours

#!/usr/bin/env python3 import matplotlib.pyplot as p,numpy as n x,y=n.meshgrid(n.linspace(-4,4,512),n.linspace(-4,4,512)) z=(1-x/2+x**4+y**3)*n.exp(-x**2-y**2)*(1-x/3-y**4)*(3-y+x**2) z+=.5*n.sin(.8*x+.6*y)+.4*n.cos(.5*x-.7*y)+.3*n.sin(.6*x-.4*y) p.contour(x,y,z,levels=n.linspace(z.min(),z.max(),25),cmap=’terrain’) p.show()

Posted in Uncategorized | Leave a comment

Xmas

#!/usr/bin/env python3 from datetime import* t=datetime.today() print(“Only”,(datetime(t.year,12,25)-t).days,”shopping days until Christmas.”)

Posted in Uncategorized | Leave a comment

Factorials

teresita:Desktop$ seq 3 | paste -sd* | bc 6 teresita:Desktop$ seq 30 | paste -sd* | bc 265252859812191058636308480000000 teresita:Desktop$ seq 300 | paste -sd* | bc 306057512216440636035370461297268629388588804173576999416776741259476533176716867465515291422477573349939147888701726368864263907759003154226842927906974559841225476930271954604008012215776252176854255965356903506788725264321896264299365204576448830388909753943489625436053225980776521270822437639449120128678675368305712293681943649956460498166450227716500185176546469340112226034729724066333258583506870150169794168850353752137554910289126407157154830282284937952636580145235233156936482233436799254594095276820608062232812387383880817049600000000000000000000000000000000000000000000000000000000000000000000000000

Posted in Uncategorized | Leave a comment

Rot13

Rot13 with Python #!/usr/bin/python3 import sys, string def rot13(s): return ”.join([chr(x.islower() and ((ord(x) – 84) % 26) + 97 or x.isupper() and ((ord(x) – 52) % 26) + 65 or ord(x)) for x in s]) for line in sys.stdin: sys.stdout.write(rot13(line))

Posted in Uncategorized | Leave a comment