Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

семестр 1 / lab15

.py
Скачиваний:
0
Добавлен:
13.05.2026
Размер:
4 Кб
Скачать
import os
clear = lambda: os.system('cls')
clear()
import numpy as np

def arrout_opti(array, clmni, dgnmb):
	import numpy as np

	s1 = ""
	s2 = ""
	s3 = ""
	rowcheck = False
	columnindex = clmni
	rowindex = 0
	nm_width = 0

	arraynp = np.array(array)
	l = arraynp.size
	
	if l % columnindex == 0:
		rowcheck = True
		rowindex = int(l / columnindex)
	else:
		rowcheck = False

	if rowcheck == False:
		print(f'Invalid data: the number of array elements is not a multiple of the number of elements in the row')
	elif rowcheck == True:
		arraynp.shape = rowindex, columnindex
		nm_width = len(str(rowindex))

		for i in range(0,10):
			s3 += " "
		for i in range(0, ((len(s3)+dgnmb+5)*columnindex + 2*columnindex) + nm_width+2):
			s1 += chr(0x2550)
			s2 += chr(0x2500)
		print(chr(0x2560)+s1+chr(0x2563))
		
		for i in range(0, rowindex):
			int(i)
			print(chr(0x2551), end=' ')
			print(f'{i+1:0{nm_width}}', end=" ")

			if i != rowindex-1:
				for j in range(0, columnindex):
					int(j)
					print(f'{s3}{arraynp[i][j]:0.{dgnmb}e}', end=" ")
				print(chr(0x2551))
				print(chr(0x255F)+s2+chr(0x2562))
			elif i == rowindex-1:
				for j in range(0, columnindex):
					int(j)
					print(f'{s3}{arraynp[i][j]:0.{dgnmb}e}', end=" ")
				print(chr(0x2551))				
		print(chr(0x255A)+s1+chr(0x255D)+chr(10))

#All data exept headings
a = np.zeros(19188)
a.shape = (1599, 12)
headings = []

#Input from file
count = 0
f = open('winequality-red.csv', 'r')
for line in f:
	if count == 0:
		headings.extend(line.split(','))
	elif count > 0:
		tmp = line.split(',')
		for j in range(0,12):
			int(j)
			int(count)
			a[count-1][j] = tmp[j]
	count += 1
f.close()

#Parameter 1 matrix
par1 = np.zeros(1599, dtype = np.float16)
par1.shape = (1599, 1)

#Parameter 2 matrix
par2 = np.zeros(1599, dtype = np.float16)
par2.shape = (1599, 1)

#Parameter 3 matrix
par3 = np.zeros(1599, dtype = np.float16)
par3.shape = (1599, 1)

#Parameter 4 matrix
par4 = np.zeros(1599, dtype = np.float16)
par4.shape = (1599, 1)

#Parameter 5 matrix
par5 = np.zeros(1599, dtype = np.float16)
par5.shape = (1599, 1)

#Parameter 6 matrix
par6 = np.zeros(1599, dtype = np.float16)
par6.shape = (1599, 1)

#Parameter 7 matrix
par7 = np.zeros(1599, dtype = np.float16)
par7.shape = (1599, 1)

#Parameter 8 matrix
par8 = np.zeros(1599, dtype = np.float16)
par8.shape = (1599, 1)

#Parameter 9 matrix
par9 = np.zeros(1599, dtype = np.float16)
par9.shape = (1599, 1)

#Parameter 10 matrix
par10 = np.zeros(1599, dtype = np.float16)
par10.shape = (1599, 1)

#Parameter 11 matrix
par11 = np.zeros(1599, dtype = np.float16)
par11.shape = (1599, 1)

for i in range(0, 1599):
	int(i)
	par1[i] = a[i][0]
	par2[i] = a[i][1]
	par3[i] = a[i][2]
	par4[i] = a[i][3]
	par5[i] = a[i][4]
	par6[i] = a[i][5]
	par7[i] = a[i][6]
	par8[i] = a[i][7]
	par9[i] = a[i][8]
	par10[i] = a[i][9]
	par11[i] = a[i][10]

#Result matrix
res = np.zeros(1599, dtype = np.float16)
res.shape = (1599, 1)

for i in range(0, 1599):
	int(i)
	res[i] = a[i][11]

#Crutches on a bicycle instead of for output
headings[11] = "quality"
out = np.zeros(60, dtype = np.float16)
out.shape = (5, 12)

for i in range(0,5):
	int(i)
	out[i][0] = par1[i]
	out[i][1] = par2[i]
	out[i][2] = par3[i]
	out[i][3] = par4[i]
	out[i][4] = par5[i]
	out[i][5] = par6[i]
	out[i][6] = par7[i]
	out[i][7] = par8[i]
	out[i][8] = par9[i]
	out[i][9] = par10[i]
	out[i][10] = par11[i]
	out[i][11] = res[i]

s1 = ""
for i in range(0,255):
	s1 += chr(0x2550)
print(chr(0x2554)+s1+chr(0x2557))
print(chr(0x2551)+" #", end=' ')
for i in range(0,12):
	int(i)
	l = len(headings[i])
	tmp = ""
	for j in range(0, 20-l):
		tmp += " "
	print(tmp+headings[i], end=" ")
print(chr(0x2551))
arrout_opti(out, 12, 4)
Соседние файлы в папке семестр 1