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

семестр 1 / arr_out_opti

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

seq = [[random.random() for _ in range(40)] for _ in range(10)]

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

	s1 = ""
	s2 = ""
	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, ((dgnmb+1)*columnindex + 2*columnindex) + nm_width+2):
			s1 += chr(0x2550)
			s2 += chr(0x2500)
		print(chr(0x2554)+s1+chr(0x2557))
		
		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'{arraynp[i][j]:1.{dgnmb}f}', end=" ")
				print(chr(0x2551))
				print(chr(0x255F)+s2+chr(0x2562))
			elif i == rowindex-1:
				for j in range(0, columnindex):
					int(j)
					print(f'{arraynp[i][j]:1.{dgnmb}f}', end=" ")
				print(chr(0x2551))				
		print(chr(0x255A)+s1+chr(0x255D)+chr(10))

arrout_opti(seq, 5, 9)
Соседние файлы в папке семестр 1