def UnireMatriciRig(a, b): import numpy as np r1 = size2(a, 1) r2 = size2(a, 2) r3 = size2(b, 1) r4 = size2(b, 2) a = np.asmatrix(a) b = np.asmatrix(b) #if asse==0.: if r1 != r3: return 0 culo = np.matrix(np.zeros((r1, r2 + r4))) righe = range(0, r1) srighe = range(0, r3) colonne = range(0, r2) scolonne = range(r2, r2 + r4) #print(righe,colonne,srighe,scolonne) for i in righe: for j in colonne: #print(i,j, a[i,j]) culo.itemset((i, j), a.item((i, j))) for i in srighe: for k in scolonne: #print(i,k, b[i,k-r2]) culo.itemset((i, k), b.item((i, k - r2))) return culo
def EstraiUnPezzo(matr, rigai, rigaf, coloi, colof): import numpy as np #print(matr) righe = size2(matr, 1) colonne = size2(matr, 2) if rigaf == "end": righenuove = righe - rigai else: righenuove = rigaf - rigai if colof == "end": colonnenuove = colonne - coloi else: colonnenuove = colof - coloi #print(righenuove,colonnenuove) nuova = np.asmatrix(np.zeros((righenuove, colonnenuove))) VetRigheGen = range(0, righenuove) VetColonGen = range(0, colonnenuove) #print(VetColonGen,VetRigheGen) #print(VetColonGen,VetRigheGen,righenuove,colonnenuove) for i in VetRigheGen: for j in VetColonGen: #print(i+rigai,j+coloi) nuova[i, j] = matr[i + rigai, j + coloi] #print(nuova) return nuova
def DentroLaFigura(x, magliax, magliay): import numpy as np from matplotlib import path """ xv =transponi(np.matrix("0.05840, 0.48375, 0.69356, 1.47478, 1.32158,1.94545, 2.16477, 1.87639, 1.18218, 0.27615,0.05840")) yv =transponi(np.matrix("0.60628, 0.04728, 0.50000, 0.50000, 0.02015, 0.18161, 0.78850, 1.13589, 1.33781, 1.04650, 0.60628")) x=UnireMatriciRig(xv,yv) IsPointInside=np.matrix([[1,2],[1,9]]) """ #print("cacacacac",size2(magliax,0)) IsPointInside = np.matrix("0 0") VetRig = size2(magliax, 1) VetCol = size2(magliax, 2) magliaz = np.asmatrix(np.zeros((VetRig, VetCol))) for i in range(VetRig): for j in range(VetCol): IsPointInside[0, 0] = magliax[i, j] IsPointInside[0, 1] = magliay[i, j] p = path.Path((x)) aha = p.contains_points(IsPointInside) #print(aha) #print(IsPointInside) aha = np.asmatrix(aha) if aha: magliaz[i, j] = 1 #}print(size2(magliaz,0)) return magliaz
def RiduciDimensioni(magliacx, magliacy, inlocale): somma = SommaDegliScalari(inlocale) r1 = 0 r2 = size2(inlocale, 1) - 1 r3 = 0 r4 = size2(inlocale, 2) - 1 somma1 = somma while somma1 == somma: r1 = r1 + 2 taron = inlocale[r1:r2, r3:r4] somma1 = SommaDegliScalari(taron) r1 = r1 - 2 somma1 = somma while somma1 == somma: r2 = r2 - 2 taron = inlocale[r1:r2, r3:r4] somma1 = SommaDegliScalari(taron) r2 = r2 + 2 somma1 = somma while somma1 == somma: r3 = r3 + 2 taron = inlocale[r1:r2, r3:r4] somma1 = SommaDegliScalari(taron) r3 = r3 - 2 somma1 = somma while somma1 == somma: r4 = r4 - 2 taron = inlocale[r1:r2, r3:r4] somma1 = SommaDegliScalari(taron) r4 = r4 + 2 magliacx = magliacx[r1:r2, r3:r4] magliacy = magliacy[r1:r2, r3:r4] inlocale = inlocale[r1:r2, r3:r4] #print(r1,r2,r3,r4) return magliacx, magliacy, inlocale
def UnireMatriciColNon(a, b): import numpy as np r1 = size2(a, 1) r2 = size2(a, 2) r3 = size2(b, 1) r4 = size2(b, 2) a = np.asmatrix(a) b = np.asmatrix(b) #if asse==0.: rmax = r2 if r4 > r2: rmax = r4 #if r2!=r4: #return 0 culo = np.matrix(np.zeros((r1 + r3, rmax))) righe = range(0, r1) srighe = range(r1, r3 + r1) colonne = range(0, r2) scolonne = range(0, r4) #print(righe,colonne,srighe,scolonne) for i in righe: for j in colonne: #print(i,j, a[i,j]) culo.itemset((i, j), a.item((i, j))) for i in srighe: for k in scolonne: #print(i,k, b[i-r1,k]) culo.itemset((i, k), b.item((i - r1, k))) return culo
def SommaDegliScalari(a): VetRigheGen = range(0, size2(a, 1)) VetColonGen = range(0, size2(a, 2)) b = 0 for i in VetRigheGen: for j in VetColonGen: b = b + a[i, j] return b
def ScalarXMatr(b, a): import numpy as np r1 = size2(a, 1) r2 = size2(a, 2) c = np.asmatrix(np.zeros((r1, r2))) VetR1 = range(0, r1) VetR2 = range(0, r2) for i in VetR1: for j in VetR2: c[i, j] = a[i, j] * b return c
def arrotonda(a, kappa): import numpy as np r1 = size2(a, 1) r2 = size2(a, 2) b = np.asmatrix(np.zeros((r1, r2))) VetR1 = range(0, r1) VetR2 = range(0, r2) for i in VetR1: for j in VetR2: b[i, j] = round(a[i, j], kappa) return b
def SommaInColonne(matrice): VetRigheGen = range(0, size2(matrice, 1)) VetColonGen = range(0, size2(matrice, 2)) import numpy as np zeris = np.zeros((1, size2(matrice, 2))) for j in VetColonGen: somma = 0 for i in VetRigheGen: somma = somma + matrice[i, j] zeris[0, j] = somma return zeris
def massimo(a): import numpy as np a = np.asmatrix(a) r1 = size2(a, 1) r2 = size2(a, 2) b = a[0, 0] VetR1 = range(0, r1) VetR2 = range(0, r2) for i in VetR1: for j in VetR2: if b < a[i, j]: b = a[i, j] return b
def listare(numero1, kk, discretizzaarchicerchi): #%prendi una figura geometrica da un file dati #from misuras import size2,UnireMatriciCol from calcolatrice.studiatore2 import studianumero1 import numpy as np numerodifiguregeneriche = size2(numero1, 1) #% dimmi quante figure vuoi inserire #%vettore_spostamento=[0 0]; #%listadicoordinate=zeros(1,4) VetRigheGen = range(0, numerodifiguregeneriche) #print(numero1) for i in VetRigheGen: calcolo = 4 ciro = np.asmatrix(numero1[i, :]) #print("primadel4",ciro) #print(type(ciro)) coordinate, b1, b2, b3, b4, b5, b6, b7, b8, peso_specifico = studianumero1( ciro, kk, calcolo, discretizzaarchicerchi, 0, 0) #print("cazzu cazzu",coordinate) #mi servono solo le variablili "coordinate" e "peso:specifico" coordinate = np.asmatrix(coordinate) #print("dopoil4",coordinate) if i == 0: listadicoordinate = coordinate listadicoordinate = np.asmatrix(listadicoordinate) #print("nell'uno",listadicoordinate) else: listadicoordinate = UnireMatriciCol(listadicoordinate, coordinate) #print("neidopo",listadicoordinate) listadicoordinate = np.asmatrix(listadicoordinate) return listadicoordinate """
def CancellaUnaRiga(matr, riga): import numpy as np from misuras import size2 righevecchie = size2(matr, 1) colonnevecchie = size2(matr, 2) nuova = np.zeros((righevecchie - 1, colonnevecchie)) VetRigheGen = range(0, righevecchie + 1) VetCOlonGen = range(0, colonnevecchie + 1) for i in VetRigheGen: for j in VetCOlonGen: if i < riga: nuova[i, j] = matr[i, j] elif i == riga: print("nada") else: nuova[i - 1, j] = matr[i, j] return nuova
def EstraiUnaColonna(matr, colonna): import numpy as np righevecchie = size2(matr, 1) nuova = np.zeros((righevecchie, 1)) VetRigheGen = range(0, righevecchie) for i in VetRigheGen: if i == colonna: nuova[i, 0] = matr[i, colonna] return nuova
def rigacnf(riga1, riga2): r1 = size2(riga1, 1) r2 = size2(riga1, 2) r3 = size2(riga2, 1) r4 = size2(riga2, 2) r5 = SommaDegliScalari(riga1) r6 = SommaDegliScalari(riga2) m = 1 dipende = 0 #print(r1,r2,r3,r4,r5,r6) if r1 == r3 and r2 == r4 and r5 == r6: for i in range(0, r1): for j in range(0, r2): if riga1[i, j] != riga2[i, j]: m = m + 1 if m == 1: dipende = 1 else: dipende = 0 return dipende
def CancDoppioni(a): #from misuras import size2, rigacnf,UnireMatriciCol import numpy as np #print(a,size2(a,1),size2(a,2)) a = np.asmatrix(a) punti = size2(a, 1) b = np.asmatrix(a[0, :]) VetPunti = range(1, punti) #deve partire dalla seconda riga VetCol = range(0, 2) #print(punti,b,VetPunti,VetCol) #print(VetCol) for i in VetPunti: kk = 7 VetCol = range(0, size2(b, 1)) #print(VetCol) #print(b) #print(a[i,:]) #☺print(VetCol) for j in VetCol: r1 = np.asmatrix(b[j, :]) r2 = np.asmatrix(a[i, :]) ee = rigacnf(r1, r2) #print(ee) kk = kk + ee #print(i,j,ee) #print(b) #print(r1,r2,ee) #print("kk",kk,a[i,:]) if kk == 7: k = a[i, :] k = np.asmatrix(k) #print("a",np.size(a,0),np.size(a,1)) #print("k",np.size(k,0),np.size(k,1)) b = UnireMatriciCol(b, k) # print(b) #print(b,size2(b,1),size2(b,2)) return b """
def EstraiUnaRiga(matr, riga): import numpy as np colonnevecchie = size2(matr, 2) nuova = np.zeros((1, colonnevecchie)) VetCOlonGen = range(0, colonnevecchie) """ print("riga") print(riga) print(colonnevecchie) print(np.size(matr,1)) print(np.size(matr,0)) print(np.size(nuova,1)) print(np.size(nuova,0)) print("VetCOlonGen") print(np.size(VetCOlonGen,0)) #print(VetCOlonGen) """ for j in VetCOlonGen: #print(j) nuova[0, j] = matr[riga, j] return nuova
def ProdVettoriale(a, b): import numpy as np if size2(a, 1) == size2(b, 2): VetRigheGen = range(0, size2(a, 2)) VetColonGen = range(0, size2(b, 1)) c = np.zeros(size2(a, 2), size2(b, 1)) i = 0 j = 0 for i in VetRigheGen: c[i, j] = 0 for j in VetColonGen: c[i, j] = c[i, j] + a[i, j] * b[i, j] else: print("non è un risultato") c = 0 return c