Last active
July 10, 2018 07:13
-
-
Save d0uji/ce57aca931324a2b3eb2da75a59c3494 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: cp1251 | |
import numpy as np | |
import sys | |
def read_matrix(type=float): | |
n = int(input("Введите n: ")) | |
m = int(input("Введите m: ")) | |
a = [] | |
for i in range(n): | |
a.append(list(map(type, input().split()))) | |
if len(a[i]) != m: | |
print("Неправильное количество столбцов!") | |
sys.exit() | |
a = np.array(a) | |
return a | |
# 2 | |
a = read_matrix() | |
print("Max:", max(a.mean(1))) | |
# 7 | |
a = read_matrix() | |
s = a.sum() | |
print("SUM:", s) | |
col = np.array(sum(a.T)) * 1/s # a.T - транспонирование | |
a = np.append(a, col.reshape((len(col), 1)), 1) # reshape - переворачиваем вектор | |
print(a) | |
# 12 | |
a = read_matrix() | |
max_vals = np.amax(a, 1) | |
a = np.divide(a, max_vals.reshape((len(max_vals), 1))) # делим строки | |
print(a) | |
# 17 | |
a = read_matrix() | |
l = int(input("Введите L: ")) # счёт с нуля | |
row = list(map(float, input("Введите строку:\n").split())) | |
a = np.insert(a, l, row, 0) | |
print(a) | |
# 22 | |
a = read_matrix(type=int) | |
col = np.array(sum(a.T)) % 2 | |
a = np.append(a, col.reshape((len(col), 1)), 1) | |
print(a) | |
# 27 | |
a = read_matrix(type=int) | |
h = int(input("Введите h: ")) | |
print("Строки, имеющие ", h, ": ", sep="", end="") | |
print(*(i for i in range(len(a)) if h in a[i])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment