Python'da Matris için Varyans, Standart Sapma, Minimum, Maximum, Ortalama değerlerini bulma
In [25]:
from random import randint
def create_A_vector(size):
my_vector=[]
for i in range(size):
my_vector.append(randint(0,9))
return my_vector
def create_a_matrix(m,n):
my_matrix=[]
for i in range(m):
my_matrix.append(create_A_vector(n))
return my_matrix
In [26]:
def maxBul(dizi):
max=dizi[0][0]
i=1
for i in range(len(dizi)):
for j in range(len(dizi[0])):
if(max<dizi[i][j]):
max=dizi[i][j]
return max
def minBul(dizi):
min=dizi[0][0]
i=1
for i in range(len(dizi)):
for j in range(len(dizi[0])):
if(min>dizi[i][j]):
min=dizi[i][j]
return min
def ortalama(dizi):
toplam = 0
for i in range(len(dizi)):
for j in range(len(dizi[0])):
toplam += dizi[i][j]
miktar = len(dizi)*len(dizi[0])
return toplam/miktar
In [27]:
dizi=create_a_matrix(3,3)
print(dizi)
In [28]:
maxBul(dizi)
Out[28]:
In [29]:
minBul(dizi)
Out[29]:
In [30]:
ortalama(dizi)
Out[30]:
In [31]:
import math
def varyans(dizi,mean):
top=0
for i in range (len(dizi)):
for j in range(len(dizi[0])):
dizi[i][j]-=mean
dizi[i][j]*=dizi[i][j]
i=0
j=0
for i in range (len(dizi)):
for j in range(len(dizi[0])):
top+=dizi[i][j]
return top/(len(dizi)*len(dizi[0]))
def standarsapma(varyans_degeri):
stsapma = math.sqrt(varyans_degeri)
return stsapma
In [32]:
mean=ortalama(dizi)
varyans_degeri=varyans(dizi,mean)
varyans_degeri
Out[32]:
In [33]:
standarsapma(varyans_degeri)
Out[33]:
In [35]:
def solve(matrix, mul):
width = len(matrix)
if width == 1:
return mul * matrix[0][0]
else:
sign = -1
total = 0
for i in range(width):
m = []
for j in range(1, width):
buff = []
for k in range(width):
if k != i:
buff.append(matrix[j][k])
m.append(buff)
sign *= -1
total += mul * solve(m, sign * matrix[0][i])
return total
In [36]:
#matrix = [[1,-2,3],[0,-3,-4],[0,0,-3]]
print(solve(dizi, 1))
In [ ]:
Yorumlar
Yorum Gönder