import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
import time
plt.figure(1)
fuenf=mpimg.imread('356.png')
plt.imshow(fuenf, cmap='gray')
print(fuenf.shape)
plt.figure(2)
weka=mpimg.imread('wekaralle.png')
plt.imshow(weka)
print(weka.shape)
newWeka = np.copy(weka)
t = time.time()
for x in range(0,800):
for y in range(0,800):
newWeka[x,y,0] = max(1 - (x/400 - 1)**2 - (y/400-1)**2,0)
elapsed = time.time() - t
print ("Benoetigte Zeit(s): " + str(elapsed))
plt.figure(3)
plt.imshow(newWeka)
newWeka2 = np.copy(weka)
t = time.time()
xv, yv = np.meshgrid(np.arange(0, 800),np.arange(0, 800))
newWeka2[:,:,0] = np.maximum(1 - (xv/400 - 1)**2 - (yv/400-1)**2,0)
del(xv, yv)
elapsed = time.time() - t
print ("Benoetigte Zeit(s): " + str(elapsed))
plt.figure(4)
plt.imshow(newWeka2[...,:3]@[0.299, 0.587, 0.114], cmap='gray')
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
import numpy as np
from scipy import interpolate
import matplotlib.pyplot as plt
A = np.zeros([22,2])
A[:,0] = np.arange(0, 43, 2)
A[0:11,1] = [2, 6, 9, 12, 14, 16, 17.5, 18.5, 20, 20.5, 21.5]
A[11:22,1] = [22, 22.5, 22.7, 23.5, 23.5, 23.7, 24, 24, 24.2, 24.2, 24.5]
plt.plot(A[:,0], A[:,1], 'o', label="Messwerte", c='k')
plt.xlabel('Zeit [s]')
plt.ylabel('Spannung [V]')
plt.hold(True)
p2 = interpolate.lagrange(A[[0 , 10 ,21 ],0], A[[0 , 10 ,21 ],1])
xnew = np.arange(-2, 50, 2)
ynew = p2(xnew)
error = (( p2(A[:,0]) - A[:,1] )**2).sum()
print('P2 => Quadratische Fehler: %.4e; gemittelt %.4e.' % (error, error/22)) #*\label{lst:p:13:line:17}
plt.plot(xnew, ynew, label="Polynome Ordnung 2", linestyle='-', c='k')
p5 = interpolate.lagrange(A[0:22:4,0], A[0:22:4,1])
xnew = np.arange(-2, 50, 2)
ynew = p5(xnew)
error = (( p5(A[:,0]) - A[:,1] )**2).sum()
print('P5 => Quaratische Fehler: %.4e; gemittelt %.4e.' % (error, error/22)) #*\label{lst:p:13:line:23}
plt.plot(xnew, ynew,label="Polynome Ordnung 5", linestyle='--', c='r') #*\label{buildMeshFilter4}
plt.legend(loc='lower right')
plt.show()
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
import numpy as np
fString = open("iris.data","r")
fFloat = open("iris.csv","w")
for line in fString:
line = line.replace("Iris-setosa", "1")
line = line.replace("Iris-versicolor", "2")
line = line.replace("Iris-virginica", "3")
fFloat.write(line)
fString.close()
fFloat.close()
fFloat = open("iris.csv","r")
#header = fFloat.readline().rstrip('\n') # skip the header
#ColumnNames = header.split(',')
dataset = np.loadtxt(fFloat, delimiter=",")
fFloat.close()
import matplotlib.pyplot as plt
fig = plt.figure(1)
ax = fig.add_subplot(2,2,1)
ax.scatter(dataset[0:50,0],dataset[0:50,1],c='red',s=60,alpha=0.6)
ax.scatter(dataset[50:100,0],dataset[50:100,1],c='green',marker='^',s=60,alpha=0.6)
ax.scatter(dataset[100:150,0],dataset[100:150,1],c='blue',marker='*',s=80,alpha=0.6)
ax.set_xlabel('Kelchblattlaenge (cm)')
ax.set_ylabel('Kelchblattbreite (cm)')
ax.grid(True,linestyle='-',color='0.75')
ax = fig.add_subplot(2,2,2)
ax.scatter(dataset[0:50,2],dataset[0:50,3],c='red',s=60,alpha=0.6)
ax.scatter(dataset[50:100,2],dataset[50:100,3],c='green',marker='^',s=60,alpha=0.6)
ax.scatter(dataset[100:150,2],dataset[100:150,3],c='blue',marker='*',s=80,alpha=0.6)
ax.set_xlabel('Kronblattlaenge (cm)')
ax.set_ylabel('Kronblattbreite (cm)')
ax.grid(True,linestyle='-',color='0.75')
ax = fig.add_subplot(2,2,3)
ax.scatter(dataset[0:50,0],dataset[0:50,2],c='red',s=60,alpha=0.6)
ax.scatter(dataset[50:100,0],dataset[50:100,2],c='green',marker='^',s=60,alpha=0.6)
ax.scatter(dataset[100:150,0],dataset[100:150,2],c='blue',marker='*',s=80,alpha=0.6)
ax.set_xlabel('Kelchblattlaenge (cm)')
ax.set_ylabel('Kronblattlaenge (cm)')
ax.grid(True,linestyle='-',color='0.75')
ax = fig.add_subplot(2,2,4)
ax.scatter(dataset[0:50,1],dataset[0:50,3],c='red',s=60,alpha=0.6)
ax.scatter(dataset[50:100,1],dataset[50:100,3],c='green',marker='^',s=60,alpha=0.6)
ax.scatter(dataset[100:150,1],dataset[100:150,3],c='blue',marker='*',s=80,alpha=0.6)
ax.set_xlabel('Kelchblattbreite (cm)')
ax.set_ylabel('Kronblattbreite (cm)')
ax.grid(True,linestyle='-',color='0.75')
plt.tight_layout()
plt.show(block=False)
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure(2)
ax = fig.add_subplot(1,1,1, projection='3d')
ax.scatter(dataset[0:50,1],dataset[0:50,2],dataset[0:50,3],c='red',s=60,alpha=0.6)
ax.scatter(dataset[50:100,1],dataset[50:100,2],dataset[50:100,3],c='green',marker='^',s=60,alpha=0.6)
ax.scatter(dataset[100:150,1],dataset[100:150,2],dataset[100:150,3],c='blue',marker='*',s=80,alpha=0.6)
ax.set_xlabel('Kelchblattbreite (cm)')
ax.set_ylabel('Kronblattlaenge (cm)')
ax.set_zlabel('Kronblattbreite (cm)')
plt.show()
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
foo = 21;
if foo == 42:
print("This is the answer")
elif foo == 21:
print('At least ...')
print('it is half of the truth')
else:
print("I'm sorry, Dave, I'm afraid I can't do that.")
wurzel = foo
while abs(wurzel**2 - foo) > 10**-7 :
wurzel = 0.5 * (wurzel + foo/wurzel)
print("Die Wurzel von %e ist %e" % (foo,wurzel) )
autoren = ["Douglas Adams","Isaac Asimov", "Terry Pratchett", "Iain Banks"]
for name in autoren:
print(name)
for i in range(1,11,2):
print(i)
::::::::::::::::::::::::::::::::::::::::::::::::::::::
import math
class kreis():
def __init__(self,r,x,y):
if r<0 br=""> r=0
self.r = r
self.mx = x
self.my = y
def abstand(self,x,y):
d = math.sqrt((self.mx-x)**2 + (self.my-y)**2)
d = d - self.r;
return(d)0>
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
class model:
def __init__(self, listeVonParametern):
pass
def fit(self, X,Y):
pass
def predict(self, X):
pass
:::::::::::::::::::::::::::::::::::::::::::::
import numpy as np
MainSet = np.arange(0,12)
Set1 = np.random.choice(12,4, replace=False)
Set2 = np.delete(MainSet, Set1
::::::::::::::::::::::::::::::::::::::::::::::::
Mittwoch, 29. Mai 2019
Abonnieren
Kommentare zum Post (Atom)
Keine Kommentare:
Kommentar veröffentlichen
Hinweis: Nur ein Mitglied dieses Blogs kann Kommentare posten.